Skip to content

Instantly share code, notes, and snippets.

@agalera
Last active August 29, 2015 14:13
Show Gist options
  • Save agalera/8b13ebc8816623f4a650 to your computer and use it in GitHub Desktop.
Save agalera/8b13ebc8816623f4a650 to your computer and use it in GitHub Desktop.
default values in ruby
#check python https://gist.github.com/kianxineki/aa10199ba96d0d4009c6
def append_values(new_value,a=[])
a.push(new_value)
return a
end
append_values("n1") # result ['n1']
rlist = append_values("n2") # result ['n2']
rlist.push("n3")
print rlist # result ['n2', 'n3']
append_values("n3") # result ['n3']
append_values("n4", []) # result ['n4']
append_values("n5") # result ['n5']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment