From: Marat Kamenschikov Date: 2010-03-27T01:11:58+09:00 Subject: changing method behavior depending on context Assume there is class A with method save which takes one param with default value (e.g. true). Class A instance gets save and behaves depending on true value. Assume there is class B with a field of type A. Calling save on this field it should behave as if save(false) was called. Outside of class B scope save method should behave originally. Something like override, but just inside of one scope. Here is some piece of code: class A def save(validate = true) validate? 束INVALID損: 束VALID損 end end class B # something very crazy def initialize @a = A.new end def save @a.save end end A.new.save # => 束INVALID損 B.new.save # => 束VALID損 A.new.save # => 束INVALID損 It is meant to be used in Rails application with ActiveRecord objects, but it really doesn't matter much. The most simple way here is probably examining caller list, but is there a way to redef a method inside of other class' scope? -- Posted via http://www.ruby-forum.com/.