puts $global
puts local
[alexg@powerbook]/Users/alexg/Desktop(30): ruby main.rb
10
main.rb:4: undefined local variable or method `local' for main:Object (NameError)
Alex Gutteridge
Bioinformatics Center
Kyoto University
···
On 7 Sep 2007, at 14:17, Todd A. Jacobs wrote:
Contrary to my expectations, if I have some variable assignments in an
external file, I can't simply call:
load rcfile
to have it sourced. Instead, I found myself having to do this:
On Fri, 2007-07-09 at 14:17 +0900, Todd A. Jacobs wrote:
Contrary to my expectations, if I have some variable assignments in an
external file, I can't simply call:
load rcfile
to have it sourced. Instead, I found myself having to do this:
IO.foreach(rcfile) do |line|
eval line
end
which seems lame. Is there a better way?
--
Michael T. Richter <ttmrichter@gmail.com> (GoogleTalk:
ttmrichter@gmail.com)
So much of what we call management consists in making it difficult for
people to work. (Peter Drucker)
Contrary to my expectations, if I have some variable
assignments in an external file, I can't simply call:
load rcfile
Load starts a new scope without reusing the local scope. Eval
starts a new scope with reusing the local scope. So, use eval
instead. But you should "define" the vars before loading them.
It is also unsafe - not only because of the eval but also because this
will give errors for expressions that span multiple lines. The easy
fix would be
eval(File.read(rc_file))
But I'd rather resort to one of the other suggestions (namely using
local variables).
Kind regards
robert
···
2007/9/7, Todd A. Jacobs <tjacobs-sndr-019fdb@codegnome.org>:
Contrary to my expectations, if I have some variable assignments in an
external file, I can't simply call:
load rcfile
to have it sourced. Instead, I found myself having to do this:
2007/9/7, Michael T. Richter <ttmrichter@gmail.com>:
On Fri, 2007-07-09 at 14:17 +0900, Todd A. Jacobs wrote:
Contrary to my expectations, if I have some variable assignments in an
external file, I can't simply call:
load rcfile
to have it sourced. Instead, I found myself having to do this:
That was intended to read "global" of course. Sorry for the noise.
robert
···
2007/9/7, Robert Klemme <shortcutter@googlemail.com>:
2007/9/7, Todd A. Jacobs <tjacobs-sndr-019fdb@codegnome.org>:
> Contrary to my expectations, if I have some variable assignments in an
> external file, I can't simply call:
>
> load rcfile
>
> to have it sourced. Instead, I found myself having to do this:
>
> IO.foreach(rcfile) do |line|
> eval line
> end
>
> which seems lame. Is there a better way?
It is also unsafe - not only because of the eval but also because this
will give errors for expressions that span multiple lines. The easy
fix would be
eval(File.read(rc_file))
But I'd rather resort to one of the other suggestions (namely using
local variables).