Skip to content

Instantly share code, notes, and snippets.

@sshao
Last active August 29, 2015 14:21
Show Gist options
  • Save sshao/8d26bd8c9a50e5b4b2fb to your computer and use it in GitHub Desktop.
Save sshao/8d26bd8c9a50e5b4b2fb to your computer and use it in GitHub Desktop.
$ ruby -v test.rb
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
t.value: accessor-set value. didn't go through the defined method!
module TestModule
define_method "value=".to_sym do |v|
instance_variable_set("@value".to_sym, "defined method set this value")
end
end
class Test
include TestModule
attr_accessor :value
end
t = Test.new
t.value = "accessor-set value. didn't go through the defined method!"
puts "t.value: #{t.value}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment