[#401849] If statement — Masoud Ahmadi <lists@...>

Will anyone be able to point out what I am doing wrong.

15 messages 2012/12/02

[#401987] Trying to get "translator" to work — JD KF <lists@...>

So, basically, I'm trying to get the below code to work properly for

12 messages 2012/12/06

[#402012] Need help to select some listbox item in different listbox together — Jonathan Masato <lists@...>

Hello,

10 messages 2012/12/07

[#402045] if n belongs to set a and m belongs to set b repeat some steps, How? — "zubair a." <lists@...>

We can do so in java and similar languages like:

11 messages 2012/12/08

[#402078] Time.new(2001, 12, 3).to_i returns wrong value — Robert Buck <lists@...>

I am doing something that not many do, I am writing a database driver

9 messages 2012/12/09

[#402145] How I can create/extract a variable/hash into the current binding in Ruby? — Ramon de C Valle <rcvalle@...>

Hi,

12 messages 2012/12/12

[#402205] Wondering About Flatiron School — "Kevin Y." <lists@...>

Hi everyone!,

35 messages 2012/12/15
[#402207] Re: Wondering About Flatiron School — Chad Perrin <code@...> 2012/12/15

On Sat, Dec 15, 2012 at 11:51:08AM +0900, Kevin Y. wrote:

[#402214] Ruby quick reference arranged in ASCII sequence? — Old Grantonian <lists@...>

As a ruby beginner, I would be grateful for any links to a ruby

17 messages 2012/12/15

[#402226] print - and strip text between tags using Nokogiri — Paul Mena <lists@...>

I'm a Ruby Newbie trying to write a program to process thousands of HTML

13 messages 2012/12/15

[#402332] Perl to Ruby: regex captures to assignment. — "Derrick B." <lists@...>

Hello all,

37 messages 2012/12/19
[#402342] Re: Perl to Ruby: regex captures to assignment. — "Derrick B." <lists@...> 2012/12/20

First of all, thanks for the fast responses!

[#402352] Re: Perl to Ruby: regex captures to assignment. — Robert Klemme <shortcutter@...> 2012/12/20

On Thu, Dec 20, 2012 at 1:38 AM, Derrick B. <lists@ruby-forum.com> wrote:

[#402357] Re: Perl to Ruby: regex captures to assignment. — "Derrick B." <lists@...> 2012/12/20

Robert Klemme wrote in post #1089733:

[#402359] trying to strip characters from a line — Paul Mena <lists@...>

I'm reading a table from a MySQL database and then processing it row by

18 messages 2012/12/20

[#402394] simple division: -9 / 5 = -2 what? — "Derrick B." <lists@...>

$ irb

13 messages 2012/12/22

[#402412] POLS and string-handling — Paul Magnussen <lists@...>

Hi,

14 messages 2012/12/22

[#402460] "Open" dialog of Windows — "Damián M. González" <lists@...>

Hi guys, been researching about pop up the "open" file dialog of

11 messages 2012/12/24

[#402466] How do I install Ruby on my Ubuntu 12.10 partition. — Kaye Ng <lists@...>

I already have Ruby installed on my Windows 7 partition.

23 messages 2012/12/25

[#402510] Ruby Association Certified Ruby Programmer — Sean Westfall <lists@...>

How well respected is this certification in the industry: Ruby

27 messages 2012/12/27
[#402528] Re: Ruby Association Certified Ruby Programmer — Peter Hickman <peterhickman386@...> 2012/12/27

On 27 December 2012 01:28, Sean Westfall <lists@ruby-forum.com> wrote:

[#402555] numeric? — Brandon Weaver <keystonelemur@...>

I've found a bit of an annoyance trying to find out if a number is numeric

20 messages 2012/12/27

[#402580] Ruby Koans regarding Hashes. — "Derrick B." <lists@...>

I am trying to understand this, so let me know how I do. :) I know

18 messages 2012/12/28

[#402609] can't open new ruby program under "new" context menu — "Lee V." <lists@...>

I'm stuck on the new version at trying to do something very simple.

10 messages 2012/12/28

[#402642] require "test/unit" — "Mattias A." <lists@...>

Hi,

17 messages 2012/12/29
[#402667] Re: require "test/unit" — "Mattias A." <lists@...> 2012/12/31

Hi Dami=C3=A1n M. Gonz=C3=A1lez!

[#402747] Re: require "test/unit" — "Derrick B." <lists@...> 2013/01/04

Mattias A. wrote in post #1090700:

[#402749] Re: require "test/unit" — sto.mar@... 2013/01/04

Am 04.01.2013 19:48, schrieb Derrick B.:

Re: How I can create/extract a variable/hash into the current binding in Ruby?

From: Arlen Christian Mart Cuss <ar@...>
Date: 2012-12-12 10:57:27 UTC
List: ruby-talk #402152
To expand on Jan's comments, note the difference in disassemblies:

>> puts RubyVM::InstructionSequence.disasm lambda { eval 'x =3D 1'; puts x =
}
=3D=3D disasm: <RubyVM::InstructionSequence:block in irb_binding@(irb)>=3D=
=3D=3D=3D=3D
=3D=3D catch table
| catch type: redo   st: 0000 ed: 0028 sp: 0000 cont: 0000
| catch type: next   st: 0000 ed: 0028 sp: 0000 cont: 0028
|------------------------------------------------------------------------
0000 trace            1                                               (   3=
)
0002 putself
0003 putstring        "x =3D 1"
0005 send             :eval, 1, nil, 8, <ic:0>
0011 pop
0012 trace            1
0014 putself
0015 putself
0016 send             :x, 0, nil, 24, <ic:1>
0022 send             :puts, 1, nil, 8, <ic:2>
0028 leave
=3D> nil
>> puts RubyVM::InstructionSequence.disasm lambda { x =3D nil; eval 'x =3D =
1';
puts x }
=3D=3D disasm: <RubyVM::InstructionSequence:block in irb_binding@(irb)>=3D=
=3D=3D=3D=3D
=3D=3D catch table
| catch type: redo   st: 0000 ed: 0030 sp: 0000 cont: 0000
| catch type: next   st: 0000 ed: 0030 sp: 0000 cont: 0030
|------------------------------------------------------------------------
local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1] s1)
[ 2] x
0000 trace            1                                               (   4=
)
0002 putnil
0003 setdynamic       x, 0
0006 trace            1
0008 putself
0009 putstring        "x =3D 1"
0011 send             :eval, 1, nil, 8, <ic:0>
0017 pop
0018 trace            1
0020 putself
0021 getdynamic       x, 0
0024 send             :puts, 1, nil, 8, <ic:1>
0030 leave
=3D> nil

In the first instance, the parser decides that, having seen no local x, it
must be a function call, and so "0016 send :x, 0, nil, 24, <ic:1>" is
emitted.

In the second, having already seen an x ("0003 setdynamic x, 0"), it knows
that it is referring to the local var, so it emits "0021 getdynamic x, 0"
instead of a call.

Unfortunately, there's no in between where it could refer to either a local
or function, because the compiler needs to know all locally-referable
variables in order to emit the instructions; "setdynamic x, 0" is actually
"setdynamic 2, 0" (note the 'local table' before the instructions in the
second disassembly, and the total lack of same in the first one), which is
why local variables are so fast; they're just direct offsets from the local
frame pointer<http://lifegoo.pluskid.org/upload/doc/yarv/yarv_iset.html#det=
ail-1>
("environment
pointer" as of June
2012<http://comments.gmane.org/gmane.comp.lang.ruby.cvs/39182>
).

So, in short, VM constraints are responsible for this being impossible. You
could either just say 'a =3D b =3D c =3D d =3D =E2=80=A6 =3D nil' before yo=
ur hash.extract to
make them findable, or find a possibly "more Ruby" way. :)

=E2=80=94 Arlen


On Wed, Dec 12, 2012 at 9:23 PM, Jan E. <lists@ruby-forum.com> wrote:

> Hi,
>
> I'm no expert on this stuff, but I think it's a problem of the Ruby
> interpreter determining variables while it parses the code:
>
> eval 'x =3D 1'
> puts x
>
> This doesn't work, because the parser doesn't "see" the eval stuff. It
> doesn't find an assignment for "x", so it assumes it's a method (which
> leads to a NameError).
>
> If, however, you set "x" to an arbitrary value beforehands, it correctly
> regognizes "x" as a variable:
>
> x =3D nil
> eval 'x =3D 1'
> puts x
>
> Apart from the technical stuff: I don't find it a good idea to just dump
> variables into a binding, because it's just too much "magic". It makes
> it hard to keep track of which variable has which value. And I can't
> think of any good reason to do that when you're programming
> object-oriented.
>
> Did you get the idea from PHP? Because that language is notorious for
> dumping values into all kinds of contexts, which has lead and still
> leads to gigantic security problems.
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

In This Thread