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 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?
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs