I don't understand the concept of Ruby operators. What is the difference between '<' and 'xyz' method? -


class computation    def initialize(&block)     @action = block   end    def result     @result ||= @action.call   end    def xyz(other)    end    def <(other)     result < other.result   end   end  = computation.new { 1 + 1 } b = computation.new { 4*5 }    p < b  #=> true p xyz b #=> `<main>': undefined method `xyz' main:objec 

i don't understand why '<' method works , 'xyz' method returns error ?

in ruby < > + - etc operators, can call operators without dot, , off course can redefine operators (what doing here).

in case of xyz string, , when called without dot ruby treats differently.

a.xyz b evaluates a.xyz(b)

a xyz b evaluates a(xyz(b)) , since global scope object, throw undefined method 'xyz' main:object


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -