No Credit Check Payday Loans

An interesting class naming behavior in Ruby

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?

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