Ruby class_eval example
C = Class.new
C.class_eval do
def some_method
puts "Created in class_eval"
end
end
c = C.new
c.some_method
var = 'test class_eval'
C.class_eval {define_method('talk') {puts var}}
c.talk
C = Class.new
C.class_eval do
def some_method
puts "Created in class_eval"
end
end
c = C.new
c.some_method
var = 'test class_eval'
C.class_eval {define_method('talk') {puts var}}
c.talk
发表者 俞 伟军 位置在: 6/13/2007 11:56:00 PM
标签: class_eval , Example , Ruby
No comments :
Post a Comment