Posts

Showing posts from November, 2008

Adam Wiggins' RestClient at SBonRails Ligtning Talk

Full Screen : http://docs.google.com/Present?docid=d5vwc72_570dggpbshh&skipauth=true

Making sense out of ruby's dynamic method calls

Case 1: def n puts "inside n" end def m(&m2) m2.call end m(&method(:n)) m() {puts "hello"} >> inside n >> hello Case 2: def m() yield end m(&method(:n)) m() {puts "hello"} >> inside n >> hello Case 3: def m(&m2) m2.call yield p m2.class end m(&method(:n)) m() {puts "hello"} >> inside n >> inside n >> Proc >> hello >> hello >> Proc Case 4: (Adding checking before calling) def m(&m2) m2.call unless m2.nil? end def m yield if block_given? end Case 5: p = Proc.new(&method(:n)) p.call m(&p) >> inside n #p.call >> inside n #m(&p) Case 6: p = Proc.new() {puts 'hello'} p.call m(&p) >> hello #p.call >> hello #m(&p) Case 7: p = method(:n).to_proc m(&p) >> inside n Conclusions and Summary - The decision of using yield or call in a method does not affect how the method is invoked. It can be given a block or a &a