1. eval(statement) will create it's own scope and run the commands in
that scope, while eval statement will run the commands in the global scope.
2. I can assign something to, for example, `puts` and the `puts`
statement will work just like without the assignment.
Could you please show real code that exhibits the behaviour you're
wondering about?
···
On Sat, Oct 26, 2013 at 9:08 PM, Kalinni Gorzkis <musicdenotation@gmail.com>wrote:
Ruby has a peculiar behavior:
1. eval(statement) will create it's own scope and run the commands in
that scope, while eval statement will run the commands in the global scope.
2. I can assign something to, for example, `puts` and the `puts`
statement will work just like without the assignment.
eval(statement) will create it's own scope and run the commands in that
scope, while eval statement will run the commands in the global scope.
No. There's no difference between calling eval with or without
brackets other than syntax issues because of precedence. But eval
behaves identical in both cases. If at all behavior can differ based
on the second optional argument which you can use to pass another
binding.
I can assign something to, for example, `puts` and the `puts` statement will
work just like without the assignment.
Dark is the meaning of your words.
How does this work?
I chime in with others who have asked you to provide real code
examples that demonstrate the behavior. Please do.
Cheers
robert
···
On Sun, Oct 27, 2013 at 3:08 AM, Kalinni Gorzkis <musicdenotation@gmail.com> wrote:
puts=3
puts "Hello World!"
puts puts
eval("x=3")
puts x
eval "x=3"
puts x
···
On Sun, Oct 27, 2013 at 10:41 AM, tamouse mailing lists < tamouse.lists@gmail.com> wrote:
On Sat, Oct 26, 2013 at 9:08 PM, Kalinni Gorzkis < > musicdenotation@gmail.com> wrote:
Ruby has a peculiar behavior:
1. eval(statement) will create it's own scope and run the commands in
that scope, while eval statement will run the commands in the global scope.
2. I can assign something to, for example, `puts` and the `puts`
statement will work just like without the assignment.
How does this work?
Could you please show real code that exhibits the behaviour you're
wondering about?
In my setup no difference between eval "x=3" and eval("x=3").
Try this "before" the eval.
x = "Now the local variable exists before the eval"
eval("x=3")
puts x
eval "x=3"
puts x
IMHO eval string is evaluated as a closure like a block and the rules
for local variable scopes (at blocks) apply.
Look at this:
10.times {|n| x = n; puts x }; puts x # => Render error because 'x'
was restricted to the block.
x = "Anything before entering the block"; 10.times {|n| x = n; puts x
}; puts x # => Now, no error.
If it was an instance variable it would render no error because
instance variables rules are different.
10.times {|n| @x = n; puts @x }; puts @x # => No error, even if
instance var '@x' is not previously defined.
NOTE: Ruby 1.8 rules are different. It will probably issue you no
error in any of your examples.
Abinoam Jr.
···
On Sun, Oct 27, 2013 at 3:07 AM, Kalinni Gorzkis <musicdenotation@gmail.com> wrote:
puts=3
puts "Hello World!"
puts puts
eval("x=3")
puts x
eval "x=3"
puts x
On Sun, Oct 27, 2013 at 10:41 AM, tamouse mailing lists > <tamouse.lists@gmail.com> wrote:
On Sat, Oct 26, 2013 at 9:08 PM, Kalinni Gorzkis >> <musicdenotation@gmail.com> wrote:
Ruby has a peculiar behavior:
eval(statement) will create it's own scope and run the commands in that
scope, while eval statement will run the commands in the global scope.
I can assign something to, for example, `puts` and the `puts` statement
will work just like without the assignment.
How does this work?
Could you please show real code that exhibits the behaviour you're
wondering about?
pry(main)> just_a_var = "I am just a variable"
=> "I am just a variable"
pry(main)> puts just_a_var
I am just a variable
=> nil
pry(main)> puts
=> "some silly string"
Difference between method/messages/local vars here is all, yes?
···
On Sun, Oct 27, 2013 at 5:02 AM, Robert Klemme <shortcutter@googlemail.com>wrote:
On Sun, Oct 27, 2013 at 3:08 AM, Kalinni Gorzkis > <musicdenotation@gmail.com> wrote:
> Ruby has a peculiar behavior:
>
> eval(statement) will create it's own scope and run the commands in that
> scope, while eval statement will run the commands in the global scope.
No. There's no difference between calling eval with or without
brackets other than syntax issues because of precedence. But eval
behaves identical in both cases. If at all behavior can differ based
on the second optional argument which you can use to pass another
binding.
> I can assign something to, for example, `puts` and the `puts` statement
will
> work just like without the assignment.
Dark is the meaning of your words.
> How does this work?
I chime in with others who have asked you to provide real code
examples that demonstrate the behavior. Please do.