syntax - Defining methods with equals in Ruby
Being new to Ruby, I'm having trouble explaining to myself the behavior around method definitions within Ruby.
The example is noted below...
class Foo
def do_something(action)
action.inspect
end
def do_something_else=action
action.inspect
end
end
?> f.do_something("drive")
=> "\"drive\""
?> f.do_something_else=("drive")
=> "drive"
The first example is self explanatory. What Im trying to understand is the behavior of the second example. Other than what looks to be one producing a string literal and the other is not, what is actually happening? Why would I use one over the other?
This question and all comments follow the
"Attribution Required."
Similar questions
- How does defining [bracket] methods work in ruby?
- Defining methods inside a module in Ruby
- ruby on rails - Defining methods on the activerecord relationship
- Metaprogramming - dynamically defining class methods in Ruby
- kotlin - There was a problem defining the equals() operator
- More similar questions >>
All Answers
Leave a Reply