Ruby on Rails Friday, September 6, 2013

Love U Ruby wrote in post #1120864:
> I am confused on the second call :-
>
> class Foo
> def <<(param)
> "hi"
> end
> end
> foo = Foo.new
> foo.<<(1) # => "hi"
>
> foo << 1 # => "hi" # I didn't use `.` method,then how method `<<` has
> been called?

I would image that it works the same as it does for the +, -, *, and /
methods.

Example:
$ irb
irb(main):001:0> 5 + 7
=> 12
irb(main):002:0> 5.+(7)
=> 12

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/033bdc692487eb5166b61f1c7ee05fe5%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment