Re:RubyMotion Goes 2.0 And Gets OSX Support, Templates and P...
by 10char on Thursday May 09, 2013 @07:23PM
(#5683605)
What jballanc is saying is that yes these things are possible in Objective-C, but the technique of doing these tricks in Ruby/Motion is an order of magnitude simpler and idiomatic:
klass = Object.const_set "MySubclass", Class.new(Object)
klass.send(:attr_accessor, :foo)
klass.send(:define_method, "description") {
"<#{self.class}: foo=#{self.foo}>"
}
Here's how you'd make that class on the fly:
Here's how you'd add a description method to a newly created class: And your iVars: