Skip to content

Instantly share code, notes, and snippets.

@stubotnik
Created September 21, 2012 15:37
Show Gist options
  • Save stubotnik/3762230 to your computer and use it in GitHub Desktop.
Save stubotnik/3762230 to your computer and use it in GitHub Desktop.
uninitialized constant - padrino free example
class Thing
MY_CONST = 123
def doStuff (&block)
p "doStuff: #{self.class}" # => "doStuff: Thing"
p "doStuff: #{MY_CONST}" # => "doStuff: 123"
instance_eval &block
end
def doOtherStuff (&block)
p "doOtherStuff: #{self.class}" # => "doOtherStuff: Thing"
p "doOtherStuff: #{MY_CONST}" # => "doOtherStuff: 123"
yield
end
end
t = Thing.new
t.doStuff do
doOtherStuff do
p self.class # => Thing
p self.class.constants # => [:MY_CONST]
p Thing::MY_CONST # => 123
p MY_CONST # => NameError: uninitialized constant MY_CONST
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment