Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created July 29, 2009 01:05
Show Gist options
  • Select an option

  • Save ahoward/157793 to your computer and use it in GitHub Desktop.

Select an option

Save ahoward/157793 to your computer and use it in GitHub Desktop.
# regarding : http://gist.github.com/157782
# regarding : http://drawohara.com/post/151193800/ruby-symbol-to-hash
#
class Binding
def map *vars
vars.flatten.compact.inject({}){|h,v| h.update v => eval(v.to_s, self)}
end
alias_method '>', 'map'
end
a = 4
b = 2
c = 42
p binding > [:a, :b, :c]
p binding > :a
p binding > [:a,:c]
__END__
cfp:~ > ruby a.rb
{:a=>4, :b=>2, :c=>42}
{:a=>4}
{:a=>4, :c=>42}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment