Skip to content

Instantly share code, notes, and snippets.

@dplummer
Created September 24, 2012 21:46
Show Gist options
  • Save dplummer/3778624 to your computer and use it in GitHub Desktop.
Save dplummer/3778624 to your computer and use it in GitHub Desktop.
Struct.new block and constancts
1.8.7 :001 > Foo = Struct.new(:id) do
1.8.7 :002 > BAR = 5
1.8.7 :003?> end
=> Foo
1.8.7 :004 > BAR
=> 5
1.8.7 :005 > Foo::BAR
(irb):5: warning: toplevel constant BAR referenced by Foo::BAR
=> 5
1.9.3p194 :001 > Foo = Struct.new(:id) do
1.9.3p194 :002 > BAR = 5
1.9.3p194 :003?> end
=> Foo
1.9.3p194 :004 > BAR
=> 5
1.9.3p194 :005 > Foo::BAR
(irb):5: warning: toplevel constant BAR referenced by Foo::BAR
=> 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment