An interesting class naming behavior in Ruby

November 30th, 2007

The code explains it all:

  #!/usr/bin/env ruby
  klass = Class.new

  klass.name  # => ''
  Foo = klass
  klass.name  # => 'Foo'
  Foo.name    # => 'Foo'
  Bar = Foo
  Bar.name    # => 'Foo'

Seems strange, but oddly makes sense, huh?

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • DZone
  • Digg
  • Reddit
  • del.icio.us
  • Blue Dot
  • StumbleUpon
  • Netscape
  • Ma.gnolia
  • Slashdot
  • Technorati
  • NewsVine
  • Netvouz

One Response to “An interesting class naming behavior in Ruby”

  1. Luis Lavena Says:

    Why klass.name # => ‘Foo’ after Foo = klass makes sense? Foo is not a reference to klass, but after you Foo = nil, klass.name is still ‘Foo’ :-P

    Weird, someone can explain that? :-D

Leave a Reply

  • Viagra ordre
  • Cialis en ligne
  • Levitra en ligne
  • Propecia acheter
  • Viagra acheter
  • Acheter cialis
  • Ordre levitra
  • Ordre propecia
  • En ligne viagra
  • Vente cialis
  • Levitra bon marche
  • Propecia en ligne
  • Viagra online
  • Buy cialis
  • Order Levitra
  • Buy propecia
  • Buy viagra
  • Cheap cialis
  • Cheap Levitra
  • propecia online
  • Viagra prescription
  • Cialis online
  • Buy Levitra
  • Order propecia