[MacRuby-devel] MacRuby not finding a method that Ruby is

Edward Hynes mred at dharmagaia.com
Thu Oct 8 19:47:20 PDT 2009


Hi Laurent,

I just tried running it under 0.5 and am still getting an error.  I've  
narrowed the code down to the following:

###

  class A
    def initialize
      puts 'initialize'
    end

    def self.init
      define_method(:initialize) do |*params|
        super()
      end
    end
  end

  class B < A
    init
  end

  # Calling B.new without an argument, however, works.
  B.new nil

###

HTH,
Ed

On Oct 8, 2009, at 12:21 AM, Laurent Sansonetti wrote:

> We fixed a few 32-bit issues in trunk so you may want to give it a  
> try one more time.
>
> At least we are not maintaining 0.4 anymore, so it would be great if  
> you could try your code with trunk and let us know if the bug is  
> still there. Then we can try to reduce it and fix it :)
>
> Laurent
>
> On Oct 7, 2009, at 9:16 PM, Edward Hynes wrote:
>
>> I'm still on a 32-bit machine, so can't try 0.5 yet :^(
>>
>> I did manage to find a workaround, however, by creating an alias  
>> for the 'initialize' method and then calling it instead of 'super'  
>> inside of the 'define_method' call.
>>
>> Ed
>>
>> On Oct 7, 2009, at 10:51 PM, Matt Aimonetti wrote:
>>
>>> you might want to try your luck with 0.5
>>>
>>> - Matt
>>>
>>> On Wed, Oct 7, 2009 at 7:37 PM, Edward Hynes <mred at dharmagaia.com>  
>>> wrote:
>>> Hi,
>>>
>>> I'm attempting to use the RParsec gem under MacRuby, but am  
>>> getting a NoMethodError when it loads.  I've create a test file  
>>> that simply adds my local gem directory to the front of the  
>>> library search path and then calls "require 'rparsec'".  This file  
>>> runs fine under Ruby 1.9, but produces the following error when  
>>> called from MacRuby 0.4.
>>>
>>> /Users/ehynes/Test/Gems/rparsec/parser.rb:32:in `block in init':  
>>> super: no superclass method `initialize:' for  
>>> RParsec::ValueParser:RParsec::ValueParser (NoMethodError)
>>>       from /Users/ehynes/Test/Gems/rparsec/parsers.rb:621:in `new'
>>>       from /Users/ehynes/Test/Gems/rparsec/parsers.rb:621:in  
>>> `<module:RParsec>'
>>>       from /Users/ehynes/Test/Gems/rparsec/parsers.rb:3:in `<top  
>>> (required)>'
>>>       from /Users/ehynes/Test/Gems/rparsec.rb:3:in `require'
>>>       from /Users/ehynes/Test/Gems/rparsec.rb:3:in `block in <top  
>>> (required)>'
>>>       from /Users/ehynes/Test/Gems/rparsec.rb:2:in `each'
>>>       from /Users/ehynes/Test/Gems/rparsec.rb:2:in `<top (required) 
>>> >'
>>>       from AbcParser.rb:2:in `require'
>>>       from AbcParser.rb:2:in `<main>'
>>>
>>>
>>> The method with the error in the Parser class is:
>>>
>>> def self.init(*vars)
>>>   parser_checker = {}
>>>   vars.each_with_index do |var, i|
>>>     name = var.to_s
>>>     parser_checker[i] = var if name.include?('parser') && ! 
>>> name.include?('parsers')
>>>   end
>>>   define_method(:initialize) do |*params|
>>> --->  super()   # <--- line 32
>>>     vars.each_with_index do |var, i|
>>>       param = params[i]
>>>       if parser_checker.include? i
>>>         TypeChecker.check_arg_type Parser, param, self, i
>>>       end
>>>       instance_variable_set("@"+var.to_s, param)
>>>     end
>>>   end
>>> end
>>>
>>>
>>> Any ideas as to why Ruby can call super in the above method, but  
>>> MacRuby can't?  Is there a fix or workaround that I could use?  An  
>>> alternate parser?
>>>
>>> Thanks,
>>> Ed
>>>
>>>
>>> P.S.  I did have to change one line in the RParsec parser.rb file  
>>> to get it to run under Ruby 1.9, replacing a ':' with a 'then' in  
>>> a case statement.
>>>
>>>       $ diff parser_original.rb parser.rb
>>>       881c881
>>>       <     case c when String: c[0] else c end
>>>       ---
>>>       >     case c when String then c[0] else c end  # ':'  
>>> replaced with 'then'
>>>
>>>
>>>
>>> _______________________________________________
>>> MacRuby-devel mailing list
>>> MacRuby-devel at lists.macosforge.org
>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>>
>>> _______________________________________________
>>> MacRuby-devel mailing list
>>> MacRuby-devel at lists.macosforge.org
>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>
>> -- 
>> Edward Hynes
>> Dharma Gaia LLC
>> "Software with the Earth in Mind"
>> http://dharmagaia.com
>>
>>
>>
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-- 
Edward Hynes
Dharma Gaia LLC
"Software with the Earth in Mind"
http://dharmagaia.com





More information about the MacRuby-devel mailing list