Skip to content

Instantly share code, notes, and snippets.

@anga
Created August 28, 2012 14:46
Show Gist options
  • Save anga/3498649 to your computer and use it in GitHub Desktop.
Save anga/3498649 to your computer and use it in GitHub Desktop.
[Ruby] Basic read and write in the same function
class Foo
def foo(bar=nil)
@bar = (bar || @bar)
end
end
# Example
foo = Foo.new
foo.foo() # => nil
foo.foo(10) # => 10
foo.foo() # => 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment