Ahh I see. I don't have a copy of 1.8.6 handy to test on, but this definitely fails for MRI 1.9. It seems like getting the binding of an ostruct in 1.9 doesn't work for evaluating local variables. Perhaps they changed ostruct?
Here's what happens for me:
irb(main):020:0> ostruct = OpenStruct.new({:foo => 'bar'})
=> #<OpenStruct foo="bar">
irb(main):021:0> ostruct_binding = ostruct.send(:binding)
=> #<Binding:0x2545dd0>
irb(main):022:0> eval("foo", ostruct_binding)
NameError: undefined local variable or method `foo' for main:Object
IronRuby 1.1 aims for compatibility with ruby 1.9 (and ships standard
libraries such as ostruct from 1.9 also), so it is designed to fail with
the same errors as MRI 1.9
I'm not sure what you can do to work around it, all the best.
______________________________________________________
Orion Edwards | Technical Leader
PHONE +64 7 838 9800 | FAX +64 7 838 9801 |
EMAIL [email protected] | WEB www.gallagher.co
From: Nathan Standiford <[email protected]>
To: <[email protected]>
Date: 20/06/2012 10:53 a.m.
Subject: Re: [Ironruby-core] Problem with using OpenStruct and ERB
Sent by: [email protected]
I am trying to send the binding of the OpenStruct object not the binding
of main. I have been using this with MRI 1.8.6 for some time and works
fine.
From: [email protected] [
mailto:[email protected]] On Behalf Of Orion Edwards
Sent: Tuesday, June 19, 2012 2:23 PM
To: [email protected]
Subject: Re: [Ironruby-core] Problem with using OpenStruct and ERB
I notice that in your example, you don't declare the local variable foo
anywhere:
If I run it verbatim, both MRI and IronRuby fail with undefined method foo
(and fair enough, foo isn't defined).
When I declare foo as a local variable, both MRI and IronRuby work fine
for me.
______________________________________________________
Orion Edwards | Technical Leader
PHONE +64 7 838 9800 | FAX +64 7 838 9801 |
EMAIL [email protected] | WEB www.gallagher.co
From: Nathan Standiford <[email protected]>
To: <[email protected]>
Date: 20/06/2012 04:55 a.m.
Subject: [Ironruby-core] Problem with using OpenStruct and ERB
Sent by: [email protected]
I am using OpenStructs and ERB for template generation. In this simple
example, ruby 1.8.6 runs this fine:
require "erb"
require "ostruct"
puts ERB.new("<%=foo%>", 0, "%<>").result(OpenStruct.new({ :foo => "bar"
}).send(:binding))
However, it generates the following error when I run this in IronRuby
1.1.3.0 on .NET 4.0.30319.269:
(erb):2: undefined method `foo' for main:Object (NoMethodError)
Does anyone know how to get this to behave correctly in IronRuby?
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core
<<image/gif>>
<<image/gif>>
_______________________________________________ Ironruby-core mailing list [email protected] http://rubyforge.org/mailman/listinfo/ironruby-core
