Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
meta-class subclass relationships
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Robert Dober, post: 4584727"] Hmm seems consistent for me, although the model you expect should have some merits, I believe Smalltalk satisfies your expectations.... However there are no metaclasses in ruby, only singleton classes, naming is important here to emphasis on the difference in behavior. 635/135 > irb irb(main):001:0> a = Class::new => #<Class:0xb7d89750> irb(main):002:0> ma = class << a; self end => #<Class:#<Class:0xb7d89750>> irb(main):003:0> b = Class::new a => #<Class:0xb7d77500> irb(main):004:0> mb = class << b; self end => #<Class:#<Class:0xb7d77500>> irb(main):005:0> b < a => true irb(main):006:0> mb < ma => nil irb(main):007:0> mb.superclass => #<Class:Class> irb(main):008:0> ma.send :define_method, :a do 42 end => #<Proc:0xb7d56724@(irb):8> irb(main):009:0> ma.a NoMethodError: undefined method `a' for #<Class:#<Class:0xb7d89750>> from (irb):9 from :0 Stupid me, of course I defined a method for a irb(main):010:0> a.a => 42 irb(main):011:0> b.a => 42 which works for b too, as b < a irb(main):012:0> mma = class << ma; self end => #<Class:#<Class:#<Class:0xb7d89750>>> irb(main):013:0> mmb = class << mb; self end => #<Class:#<Class:#<Class:0xb7d77500>>> irb(main):014:0> mma.send :define_method, :ma do 42 end => #<Proc:0xb7d3e228@(irb):14> irb(main):015:0> ma.ma => 42 Now this was for ma irb(main):016:0> mb.ma NoMethodError: undefined method `ma' for #<Class:#<Class:0xb7d77500>> from (irb):16 from :0 and as mb < ma does not hold this makes sense. BTW meta caught me I should have called the guys above sa, sb, ssa and ssb :( Interesting that the Pickaxe got this wrong, never publish code you have not run ;), or maybe this changed between 1.6 and 1.8? Cheers Robert [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
meta-class subclass relationships
Top