Skip to content

Instantly share code, notes, and snippets.

@NilsHaldenwang
Created October 3, 2010 17:15
Show Gist options
  • Save NilsHaldenwang/608733 to your computer and use it in GitHub Desktop.
Save NilsHaldenwang/608733 to your computer and use it in GitHub Desktop.
nils:~/ERDL[master*]> irb
ruby-1.8.7-p302 > defined? bar
=> nil
ruby-1.8.7-p302 > bar = "a"
=> "a"
ruby-1.8.7-p302 > defined? bar
=> "local-variable"
ruby-1.8.7-p302 >
arr = []
foo = "foo"
a = defined?(foo) ? foo : false
arr << a if(a)
a = defined?(bla) ? bla : false
arr << a if(a)
puts arr.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment