Skip to content

Instantly share code, notes, and snippets.

@rentalcustard
Created August 25, 2011 14:31
Show Gist options
  • Save rentalcustard/1170796 to your computer and use it in GitHub Desktop.
Save rentalcustard/1170796 to your computer and use it in GitHub Desktop.
Ruby.
class Foo
def some_method
puts "In some_method"
def some_other_method
puts "In some other method"
"Foo"
end
"Bar"
end
end
foo = Foo.new
foo.some_method
# In some_method
# => "Bar"
foo.some_other_method
#In some other method
#=> "Foo"
class Bar
def some_method
def some_other_method
"OK"
end
end
end
Bar.new.some_other_method
# NoMethodError: undefined method `some_other_method' for #<Bar:0x000001009bf680>
Bar.new.some_method
# => nil
Bar.new.some_other_method
# => OK
class Baz
def some_method
some_var = "x"
def some_other_method
some_other_var = "y"
"#{some_var}, #{some_other_var}"
end
end
end
baz = Baz.new
baz.some_method
baz.some_other_method
# NameError: undefined local variable or method `some_var' for #<Baz:0x000001010ae2c0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment