# Differences between 1/ MRI and 2/ IronRuby+JRuby

**URL:** <https://www.ruby-forum.com/t/differences-between-1-mri-and-2-ironruby-jruby/182591>\
**Category:** IronRuby\
**Created:** [January 30, 2010, 2:14pm UTC](https://www.ruby-forum.com/t/differences-between-1-mri-and-2-ironruby-jruby/182591 "2010-01-30T14:14:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [January 30, 2010, 2:14pm UTC](https://www.ruby-forum.com/t/differences-between-1-mri-and-2-ironruby-jruby/182591/1 "2010-01-30T14:14:27Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [January 30, 2010, 2:24pm UTC](https://www.ruby-forum.com/t/differences-between-1-mri-and-2-ironruby-jruby/182591/2 "2010-01-30T14:24:59Z")

</div>

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 `’  
irb(main):020:0\>

* * *

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

On Sat, Jan 30, 2010 at 2:09 PM, Thibaut BarrÃ¨re

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [January 30, 2010, 2:41pm UTC](https://www.ruby-forum.com/t/differences-between-1-mri-and-2-ironruby-jruby/182591/3 "2010-01-30T14:41:57Z")

</div>

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])  
=\> [erb-binding.rb · GitHub](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])  
=\> [erb-binding.rb · GitHub](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

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [January 30, 2010, 3:00pm UTC](https://www.ruby-forum.com/t/differences-between-1-mri-and-2-ironruby-jruby/182591/4 "2010-01-30T15:00:41Z")

</div>

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 C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

On Sat, Jan 30, 2010 at 2:41 PM, Thibaut BarrÃ¨re

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [January 30, 2010, 3:09pm UTC](https://www.ruby-forum.com/t/differences-between-1-mri-and-2-ironruby-jruby/182591/5 "2010-01-30T15:09:28Z")

</div>

Thanks - that’s probably a 1.8 specific thing… We’ll see what others  
have  
to say on Monday 🙂

Thanks for your tests!

– Thibaut

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [February 1, 2010, 6:09pm UTC](https://www.ruby-forum.com/t/differences-between-1-mri-and-2-ironruby-jruby/182591/6 "2010-02-01T18:09:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [February 1, 2010, 5:56pm UTC](https://www.ruby-forum.com/t/differences-between-1-mri-and-2-ironruby-jruby/182591/7 "2010-02-01T17:56:52Z")

</div>

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

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] 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 [erb-binding.rb · GitHub](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

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [February 1, 2010, 7:19pm UTC](https://www.ruby-forum.com/t/differences-between-1-mri-and-2-ironruby-jruby/182591/8 "2010-02-01T19:19:27Z")

</div>

We should be doing an MSI in the next few weeks.

JD

From: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Thibaut  
BarrÃ¨re  
Sent: Monday, February 01, 2010 9:02 AM  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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:  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
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](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
