Files
2012-02-21 01:15:00 -05:00

1 line
3.1 KiB
JSON

[{"user_id": 3868, "stars": [], "topic_id": 18763, "date_created": 1302571389.5641, "message": "Is eval the only way to get the value of a local variable from a string? I.e.: >> foo = 1\n=> 1\n>> eval(\"foo\")\n=> 1", "group_id": 109, "id": 633975}, {"user_id": 3868, "stars": [], "topic_id": 18763, "date_created": 1302571422.2682941, "message": "I can see the variable *name* in local_variables, but can't get at the value aside from eval that I can see.", "group_id": 109, "id": 633990}, {"user_id": 8956, "stars": [], "topic_id": 18763, "date_created": 1302579677.064316, "message": "apparently the local variables list is generated at parse time? interesting\u2026", "group_id": 109, "id": 636519}, {"user_id": 8956, "stars": [], "topic_id": 18763, "date_created": 1302579678.5939701, "message": "http://groups.google.com/group/ruby-talk-google/browse_thread/thread/b36a49bb4944baf9?pli=1", "group_id": 109, "id": 636520}, {"user_id": 8956, "stars": [], "topic_id": 18763, "date_created": 1302579929.270148, "message": "the definition of Binding#[] from the extensions gem also seems to strongly imply that eval is the only option: http://extensions.rubyforge.org/rdoc/classes/Binding.html#M000025", "group_id": 109, "id": 636585}, {"user_id": 8956, "stars": [], "topic_id": 18763, "date_created": 1302579699.8134129, "message": "(although sadly that seems to imply that the only way to get those out is via eval, sorry)", "group_id": 109, "id": 636526}, {"user_id": 1767, "stars": [], "topic_id": 18763, "date_created": 1302613924.848249, "message": "Stupid question: What use case would require to get local variables from a string? :)", "group_id": 109, "id": 641998}, {"user_id": 5369, "stars": [], "topic_id": 18763, "date_created": 1302613717.1338811, "message": "Depending on the use case it would usually make more sense to put values you need to access by name in a hash. `values = { foo: 1, bar: 2 }`, and then instead of `eval('foo')` you just do: `values[:foo]`", "group_id": 109, "id": 641951}, {"user_id": 20844, "stars": [], "topic_id": 18763, "date_created": 1302624327.446243, "message": "in the context of rails views, use local_assigns (docs here: http://api.rubyonrails.org/classes/ActionView/Base.html)", "group_id": 109, "id": 644501}, {"user_id": 1516, "stars": [], "topic_id": 18763, "date_created": 1302630091.5951059, "message": "yeah, in plain Ruby, there's only eval(\"lvar\", binding)", "group_id": 109, "id": 646360}, {"user_id": 28874, "stars": [], "topic_id": 18763, "date_created": 1304455409.942956, "message": "@koraktor this came up in the context of writing Cucumber functional tests. We have some config variables that we want to be able to reference in a step definition, without having to put the whole variable name into the user story, which would not read well.", "group_id": 109, "id": 903184}, {"user_id": 28874, "stars": [], "topic_id": 18763, "date_created": 1304455474.73365, "message": "@rfunduk using a hash as you describe, would also work. I was being (the bad kind of) lazy and trying to avoid rewriting the existing code base in order to get this new functionality :-\\", "group_id": 109, "id": 903208}]