Forum: IronRuby Differences between 1/ MRI and 2/ IronRuby+JRuby

Posted by Thibaut Barrère (thbar)
on 2010-01-30 14:14
(Received via mailing list)
Hello,

maybe someone can shed some light on that - the question is: is there a
setting to make IronRuby works the same way MRI Ruby does by default for
what I'm describing below ? I don't think it's a bug (but well maybe it 
is,
just wondering).

Using this script http://gist.github.com/290538 , MRI has a different
behaviour than JRuby or IronRuby.

The script will work just fine in MRI, whereas in JR/IR you'll get:

(erb):2: undefined local variable or method `version' for main:Object
(NameError)
    from :1:in `eval'
    from /opt/local/share/java/jruby/lib/ruby/1.8/erb.rb:743:in `result'
    from binding-error.rb:19

(erb):1: undefined method `version' for main:Object (NoMethodError)
        from C:/IronRuby/lib/ruby/1.8/erb.rb:716:in `result'
        from binding-error.rb:19
        from :0:in `eval'

It's just like values.send(:binding) is doing nothing.

any thoughts ?

thanks,

-- Thibaut
Posted by Ivan Porto Carrero (Guest)
on 2010-01-30 14:24
(Received via mailing list)
AFAIK that shouldn't work in MRI either

+ C:\dev
» irb
irb(main):001:0> require 'erb'
=> true
irb(main):002:0>
irb(main):003:0* data = { :version => RUBY_PLATFORM }
=> {:version=>"i386-mingw32"}
irb(main):004:0>
irb(main):005:0* class Hash
irb(main):006:1>   def method_missing(method,*args)
irb(main):007:2>     if (keys.include?(method) && args.empty?)
irb(main):008:3>       self[method]
irb(main):009:3>     else
irb(main):010:3*       super
irb(main):011:3>     end
irb(main):012:2>   end
irb(main):013:1> end
=> nil
irb(main):014:0>
irb(main):015:0* x = 42
=> 42
irb(main):016:0> template = ERB.new <<-EOF
irb(main):017:0"   The value of x is: <%= version %>
irb(main):018:0" EOF
=> #<ERB:0x26a53e0 @safe_level=nil, @src="#coding:CP850\n_erbout = '';
_erbout.concat \"  The value of x is: \"; _erbout.concat(( version 
).to_s);
_erbout.concat \"\\n\"\n; _erbout.force_encoding(__ENCODING__)",
@enc=#<Encoding:CP850>, @filename=nil>
irb(main):019:0> puts template.result(data.send(:binding))
NameError: undefined local variable or method `version' for main:Object
        from (erb):1
        from C:/Ruby/lib/ruby/1.9.1/erb.rb:753:in `eval'
        from C:/Ruby/lib/ruby/1.9.1/erb.rb:753:in `result'
        from (irb):19
        from C:/Ruby/bin/irb:12:in `<main>'
irb(main):020:0>

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)



On Sat, Jan 30, 2010 at 2:09 PM, Thibaut Barrère
Posted by Thibaut Barrère (thbar)
on 2010-01-30 14:41
(Received via mailing list)
Hey Ivan,

thanks for your answer.

I redid the test on:
- Mac OS X (mri ruby 1.8.7 (2009-06-12 patchlevel 174) 
[i686-darwin10.0.0])
=> http://gist.github.com/290538#file_test_on_mac_os_x.txt
- Windows 7 (mri ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32])
=> http://gist.github.com/290538#file_test_on_windows.txt

And it works on both apparently...

There must be a reason... Which version of Ruby/IRB are you using ?

-- Thibaut
Posted by Ivan Porto Carrero (Guest)
on 2010-01-30 15:00
(Received via mailing list)
mine was on windows with ruby 1.9.1 though.. I don't have a 1.8 around 
to
see if that same test works with 1.8 on windows. In 1.9.1 the tweaked 
stuff
works too

+ C:\dev
» irb
irb(main):001:0> require 'erb'
=> true
irb(main):002:0> require 'ostruct'
=> true
irb(main):003:0>
irb(main):004:0* class OpenStruct
irb(main):005:1>   def get_our_own_binding
irb(main):006:2>     binding
irb(main):007:2>   end
irb(main):008:1> end
=> nil
irb(main):009:0>
irb(main):010:0* class Templator
irb(main):011:1>   def self.render(template,values)
irb(main):012:2>     template = ERB.new(template)
irb(main):013:2>     context = OpenStruct.new(values)
irb(main):014:2>     template.result(context.get_our_own_binding)
irb(main):015:2>   end
irb(main):016:1> end
=> nil
irb(main):017:0>
irb(main):018:0* template = <<-EOF
irb(main):019:0"   The value of x is: <%= version %>
irb(main):020:0" EOF
=> "  The value of x is: <%= version %>\n"
irb(main):021:0>
irb(main):022:0* puts Templator.render(template, { :version => 
RUBY_PLATFORM
})
  The value of x is: i386-mingw32
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)



On Sat, Jan 30, 2010 at 2:41 PM, Thibaut Barrère
Posted by Thibaut Barrère (thbar)
on 2010-01-30 15:09
(Received via mailing list)
Thanks - that's probably a 1.8 specific thing... We'll see what others 
have
to say on Monday :)

Thanks for your tests!

-- Thibaut
Posted by Tomas Matousek (Guest)
on 2010-02-01 17:56
(Received via mailing list)
It should work as soon as we push the latest source out.

Tomas

From: ironruby-core-bounces@rubyforge.org 
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Thibaut 
Barrère
Sent: Saturday, January 30, 2010 5:10 AM
To: ironruby-core
Subject: [Ironruby-core] Differences between 1/ MRI and 2/ 
IronRuby+JRuby

Hello,

maybe someone can shed some light on that - the question is: is there a 
setting to make IronRuby works the same way MRI Ruby does by default for 
what I'm describing below ? I don't think it's a bug (but well maybe it 
is, just wondering).

Using this script http://gist.github.com/290538 , MRI has a different 
behaviour than JRuby or IronRuby.

The script will work just fine in MRI, whereas in JR/IR you'll get:

(erb):2: undefined local variable or method `version' for main:Object 
(NameError)
    from :1:in `eval'
    from /opt/local/share/java/jruby/lib/ruby/1.8/erb.rb:743:in `result'
    from binding-error.rb:19

(erb):1: undefined method `version' for main:Object (NoMethodError)
        from C:/IronRuby/lib/ruby/1.8/erb.rb:716:in `result'
        from binding-error.rb:19
        from :0:in `eval'

It's just like values.send(:binding) is doing nothing.

any thoughts ?

thanks,

-- Thibaut
Posted by Thibaut Barrère (thbar)
on 2010-02-01 18:09
(Received via mailing list)
Hi Thomas,

> It should work as soon as we push the latest source out.

thanks for the update (note that I'm in no hurry on these bugs - I'm 
just
pushing what I find as I go, based on the MSI release, and using 
workaround
whenever necessary).

cheers,

-- Thibaut
Posted by Jim Deville (Guest)
on 2010-02-01 19:19
(Received via mailing list)
We should be doing an MSI in the next few weeks.

JD

From: ironruby-core-bounces@rubyforge.org 
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Thibaut 
Barrère
Sent: Monday, February 01, 2010 9:02 AM
To: ironruby-core@rubyforge.org
Subject: Re: [Ironruby-core] Differences between 1/ MRI and 2/ 
IronRuby+JRuby

Hi Thomas,

> It should work as soon as we push the latest source out.

thanks for the update (note that I'm in no hurry on these bugs - I'm 
just pushing what I find as I go, based on the MSI release, and using 
workaround whenever necessary).

cheers,

-- Thibaut

Tomas

From: 
ironruby-core-bounces@rubyforge.org<mailto:ironruby-core-bounces@rubyforge.org> 
[mailto:ironruby-core-bounces@rubyforge.org<mailto:ironruby-core-bounces@rubyforge.org>] 
On Behalf Of Thibaut Barrère
Sent: Saturday, January 30, 2010 5:10 AM
To: ironruby-core
Subject: [Ironruby-core] Differences between 1/ MRI and 2/ 
IronRuby+JRuby

Hello,

maybe someone can shed some light on that - the question is: is there a 
setting to make IronRuby works the same way MRI Ruby does by default for 
what I'm describing below ? I don't think it's a bug (but well maybe it 
is, just wondering).

Using this script http://gist.github.com/290538 , MRI has a different 
behaviour than JRuby or IronRuby.

The script will work just fine in MRI, whereas in JR/IR you'll get:

(erb):2: undefined local variable or method `version' for main:Object 
(NameError)
    from :1:in `eval'
    from /opt/local/share/java/jruby/lib/ruby/1.8/erb.rb:743:in `result'
    from binding-error.rb:19

(erb):1: undefined method `version' for main:Object (NoMethodError)
        from C:/IronRuby/lib/ruby/1.8/erb.rb:716:in `result'
        from binding-error.rb:19
        from :0:in `eval'

It's just like values.send(:binding) is doing nothing.

any thoughts ?

thanks,

-- Thibaut
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.