joto has quit [Read error: Connection reset by peer]
joto has joined #ruby
shokohsc51084 has joined #ruby
shokohsc5108 has quit [Ping timeout: 256 seconds]
shokohsc51084 is now known as shokohsc5108
konsolebox has quit [Ping timeout: 246 seconds]
shokohsc5108 has quit [Ping timeout: 245 seconds]
shokohsc5108 has joined #ruby
constxqt has joined #ruby
user23 has joined #ruby
konsolebox has joined #ruby
joto has quit [Read error: Connection reset by peer]
joto has joined #ruby
<ox1eef_>
Lasange++
<adam12>
good morning
<adam12>
lasagna++ :)
<ox1eef_>
I guess it should be lasanga += 1, being #ruby and all xD
<ox1eef_>
g'morning, and happy Friday!
shokohsc51083 has joined #ruby
shokohsc5108 has quit [Ping timeout: 244 seconds]
shokohsc51083 is now known as shokohsc5108
victori has quit [Ping timeout: 256 seconds]
victori has joined #ruby
tomtmym has joined #ruby
tomtmym has quit [Changing host]
tomtmym has joined #ruby
some14u has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
some14u has joined #ruby
otisolsen70 has joined #ruby
taupiqueur_shiny has quit [Remote host closed the connection]
shokohsc5108 has quit [Read error: Connection reset by peer]
taupiqueur_shiny has joined #ruby
shokohsc5108 has joined #ruby
taupiqueur_shiny has quit [Ping timeout: 246 seconds]
sam113101 has quit [Remote host closed the connection]
sam113101 has joined #ruby
_ht has joined #ruby
willfish has quit [Ping timeout: 246 seconds]
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<johnjaye>
ruby has this super generous operator overloading right
<johnjaye>
so you could define lasanga++ if you wanted to
<adam12>
johnjaye: There is no ++ in Ruby.
<adam12>
I think there's a blog post about why.
<johnjaye>
then how do things like [] and << get defined.
<johnjaye>
or are those only for the core and you can't define them as a user
<adam12>
johnjaye: I don't have a perfect example because I don't remember teh reasoning, but one of them could be that all Fixnum's are singletons.
<adam12>
johnjaye: So 1++ might return 2, but it can't mutate itself to be 2.
<adam12>
so you'd need the assignment anyways.
<johnjaye>
no i mean operators in general. can you define them in ruby
<adam12>
And nobody would do foo = foo++
<adam12>
johnjaye: Sure. You can override Integer#+ if you want (I wouldn't tho obviously :P)
<johnjaye>
so is it more that you could define ++ but it would be ambiguous
<johnjaye>
or maybe there's some check that ++ would fail while building or intepreting?
<adam12>
I am not sure `++` is a legit method name, tho `+` is. Ruby might see `++` as `Class#+` with `+` as an argument? Or it might just fail parsing all together.
m_antis has joined #ruby
hightower3 has quit [Remote host closed the connection]
hightower3 has joined #ruby
caedmon has joined #ruby
konsolebox has quit [Ping timeout: 248 seconds]
rvalue has quit [Read error: Connection reset by peer]
rvalue has joined #ruby
graywolf has joined #ruby
<ox1eef_>
adam12: Integers being immutable is definitely at least one reason. "++" suggests mutation, but you have to reassign to increment an integer in Ruby.
<ox1eef_>
You could use define_method to define ++ (or any other name AFAIK) but you couldn't call it as expected (eg foo++) since the syntax is not understood. .send(:'++') should work though.
graywolf has quit [Quit: WeeChat 4.0.2]
ua_ has quit [Excess Flood]
ua_ has joined #ruby
<johnjaye>
ah i see
<leftylink>
you could also mislead someone with a long line and hope it scrolls off the right side of their screen
<leftylink>
pandabot rb using(Module.new { refine(NilClass) { def +@; end } }); class Incrementable; def initialize(n) @n = n end; def +(_) @n += 1 end end; a = Incrementable.new(5); a++ p
<johnjaye>
f4z4: that page doesn't exactly make it clear.
<johnjaye>
but your saying you can't defin new operators
<johnjaye>
you can define methods but they start with a letter is what it says
caedmon has quit [Ping timeout: 260 seconds]
<ox1eef_>
You can define +, -, etc as you'd expect: def +(other); self + other; end - and you can define unary operators with the syntax def +@, or def !@. I think unary operators have the most potential to be used in interesting ways.
<ox1eef_>
pandabot rb class Foo; def +@; 1; end; ++Foo.new