[ create a new paste ] login | about

Link: http://codepad.org/V7TXRxmL    [ raw code | output | fork ]

clyfe - Ruby, pasted on Apr 8:
# the function must be defined in such a place 
# ... so as to "catch" the binding of the vars ... cheesy
# otherwise we're stuck with the extra param
@_binding = binding
def write_pair(p, b = @_binding)
  eval("
	local_variables.each do |v| 
	  if eval(v + \".object_id\") == " + p.object_id.to_s + "
		puts v + ': ' + \"" + p.to_s + "\"
	  end
	end
  " , b)
end

a = 5
b = 6

username1 = "tyndall"
username = "tyndall"
username3 = "tyndall"
write_pair(username)
# username: tyndall


Output:
1
username: tyndall


Create a new paste based on this one


Comments: