|
From: Rod S. <rsc...@xm...> - 2005-04-12 03:37:06
|
When I try to call __rbobj__, I get a method missing error. I think
that is because __rbobj__ is a "C" method and is not supposed to be
called on a ruby object. Let me explain my problem better.
First, I have a profile class like this:
class Profile
include Comparable
attr_reader :name;
attr_reader :birthdate;
def initialize(name, birthdate)
@name = name;
@birthdate = birthdate;
end
def to_s
"Profile: #{name}, #{birthdate}"
end
def <=>(anotherProfile)
@name <=> anotherProfile.name
end
end
The key here is the <=> method. Next, I have a controller that gets
called from elsewhere:
class ProfileTableController < OSX::NSObject
include OSX
def initialize
@profiles = []
end
def addProfile(profile)
puts profile.class
@profiles.push(profile)
@profiles.sort!
end
end
I've cut out the irrelevant code, but here's what happen. addProfile
gets called from another controller which created the pure ruby object
profile by calling Profile.new. When addProfile gets it, it has become
an OCObject. Then when addProfile is called and there is more than one
profile to sort, then profile <=> method is called and I get the
following error:
`<=>': failed to convert OSX::OCObject into String (TypeError)
In other words the name attributes of the profile objects is not a pure
ruby string. So, back to my original question. How do I put a pure ruby
object in the @profiles array instead of the OCObject (the objective-C
wrapper around the ruby object)?
Thanks,
Rod Schmidt
infiniteNIL, LLC.
On Apr 8, 2005, at 9:09 AM, kimura wataru wrote:
> Hi,
>
> method "__rbobj__" returns wrapped ruby object.
>
> RubyCocoa picks up a ruby object from a Cocoa object
> when the Cocoa object is a parameter of ruby method.
> I think we do not have to convert ruby <=> Cocoa normally.
>
> If not, please tell me more detail.
>
>
>> I want my model objects to be pure ruby objects and of course the UI
>> classes (controllers, etc.) are Cocoa objects (they inherit from
>> NSObject). However whenever a controller creates a pure ruby object
>> and
>> passes it as a parameter to a method (say to tell another controller
>> about it). The pure ruby object gets wrapped up and becomes a Cocoa
>> object. Then when I execute code that expects pure ruby objects, it
>> doesn't work. Any suggestions? Is there a way to get the pure ruby
>> object back from the wrapper?
>>
>> Thanks,
>>
>> Rod Schmidt
>> infiniteNIL, LLC.
>>
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real
> users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Rubycocoa-talk mailing list
> Rub...@li...
> https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk
>
|