Hi guys,
I get errors when I try to run some Ruby scripts in TM. NB: I don't have those errors when I run these scripts in Bash (even from inside TM) or in IRB I have "TM_RUBY /usr/local/bin/ruby" in my shell variables.
e.g.
When using erb (example taken from Programing Ruby):
--------- #!/usr/local/bin/ruby
require 'erb'
input = %{\ <% high.downto(low) do |n| # set high, low externally %> <%= n %> green bottles, hanging on the wall <%= n %> green bottles, hanging on the wall And if one green bottle should accidentally fall There'd be <%= n-1 %> green bottles, hanging on the wall <% end %> } high,low = 10, 6 erb = ERB.new(input) erb.run
-----------
I get: RubyMate r2496 running Ruby v1.8.4.
~/bin/test.rb
/Library/Application Support/TextMate/Bundles/Ruby.tmbundle/Support/ tmruby.rb:180: bad value for range (ArgumentError) from /Library/Application Support/TextMate/Bundles/Ruby.tmbundle/ Support/tmruby.rb:120
=========================================== When using 'sqlite3': ----------- #! /usr/local/bin/ruby
require 'sqlite3'
db = SQLite3::Database.new( "/Users/fatal/bin/test.db" )
p db.execute( <<-SQL SELECT * FROM posts; SQL )
db.close -----------
I get:
RubyMate r2496 running Ruby v1.8.4.
~/bin/jots/test2.rb
(eval):5: [BUG] Segmentation fault ruby 1.8.4 (2005-12-24) [powerpc- darwin8.4.0] Program exited with return code.
NB: This script works, but I get the error, sometimes scripts using sqlite3 doesn't work at all, sometimes I only get "Program exited with return code."
I have other errors of this kind, but examples are more complicated to share or I didn't take note of them.
Am I missing something? Thanks for any tips.
- Fred
I found the problem for 'sqlite3': You have to install SWIG before the sqlite3's gem. Not mentioned with the source nor the gem...
Still no answer about erb, though. Could someone try it?
Thanks,
-- Fred
On 15 Feb 2006, at 18:51, Fred B. wrote:
When using erb (example taken from Programing Ruby):
#!/usr/local/bin/ruby
require 'erb'
input = %{\ <% high.downto(low) do |n| # set high, low externally %> <%= n %> green bottles, hanging on the wall <%= n %> green bottles, hanging on the wall And if one green bottle should accidentally fall There'd be <%= n-1 %> green bottles, hanging on the wall <% end %> } high,low = 10, 6 erb = ERB.new(input) erb.run
I get: RubyMate r2496 running Ruby v1.8.4.
~/bin/test.rb
/Library/Application Support/TextMate/Bundles/Ruby.tmbundle/Support/ tmruby.rb:180: bad value for range (ArgumentError) from /Library/Application Support/TextMate/Bundles/Ruby.tmbundle/ Support/tmruby.rb:120
On 19/2/2006, at 21:05, Fred B. wrote:
Still no answer about erb, though. Could someone try it?
I’d hoped Sune would answer this one, as he’s the expert in Ruby run- time behavior :)
The problem is that for some reason erb does not see local variables when started from RubyMate (it does see globals, so change low => $low and high => $high, and it works).
This gives an exception, and RubyMate fails to properly parse that exception (hence the range error).
As to why erb does not see local variables, or why RubyMate doesn’t properly parse the exception which results from this problem, I don’t know.
Sune?
On 20/02/2006, at 10:51, Allan Odgaard wrote:
The problem is that for some reason erb does not see local variables when started from RubyMate (it does see globals, so change low => $low and high => $high, and it works).
Yes, I looked into it and the reason is that 'load' sets up a new binding to keep local variables from overflowing into the main program. Normally this wouldn't be a problem, but for some weird reason ERB's run and result take an optional binding argument, which _defaults_ to the 'magic' value TOPLEVEL_BINDING.
I don't really see why this is done, as it would seem to make more sense to just default to the current binding (which is default for eval when not given). Maybe I can change the way RubyMate invokes the user code, so I use eval instead of load. I'll look at it tomorrow.
As for the bug in RubyMate with the backtrace, I've fixed it so it at least reports the correct error.
-- Sune.