[MacRuby-devel] MacRuby classes delete/overwrite Objective-C classes?

Robert Payne robertpayne at me.com
Fri Feb 11 19:59:27 PST 2011


Hey Guys,

I'm a bit unclear on this situation then.. 

If you create an Objective-C class "MyController" with methods and then a Ruby class "MyController" the class should combine all the methods between both correct?

For instance:

Objective-C Class:
#import "MyController.h"

@implementation MyController

- (void)helloWorld {
	NSLog(@"hello world!");
}
@end

Ruby Class:
class MyController
end

Objective-C App Delegate Class:

#import "AppDelegate.h"
#import "MyController.h"

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
	MyController *c = [[MyController alloc] init];
	[c helloWorld];
}

@end

The behavior I'm expecting is to see "Hello world" in the console but it seems as if the entire Objective-C method was deleted. I don't have a method in the Ruby class called helloWorld.

Cheers,
Robert

On 12/02/2011, at 2:43 PM, Matt Aimonetti wrote:

> Mark, your answer was great, I just wanted to make sure people reading the thread in the future get a simple answer.
> You did a great job explaining why the answer was no and I'm sure it will be valuable to many.
> 
> - Matt
> 
> On Fri, Feb 11, 2011 at 5:35 PM, Mark Rada <mrada at marketcircle.com> wrote:
> One day I'll get this question answering thing done correctly. 
> 
> Sent from my iDevice
> 
> On 2011-02-11, at 20:05, Matt Aimonetti <mattaimonetti at gmail.com> wrote:
> 
>> Do MacRuby classes completely overwrite Objective-C classes if you load one in with the same class name?
>> 
>> Just to be clear, the answer is no ;)
>> 
>> - Matt
>> 
>> Sent from my iPhone
>> 
>> On Feb 11, 2011, at 17:00, Mark Rada <mrada at marketcircle.com> wrote:
>> 
>>> Hi Robert,
>>> 
>>> Classes in ruby are open, which means that if you define it in multiple places, you get one class with things from all the definitions definitions.
>>> 
>>> However, if you define the same methods, then which ever method you define last is the one that will exist. There are also techniques for concatenating methods. 
>>> 
>>> If you want two classes with the same name two remain separate, consider using a module to create a namespace. 
>>> 
>>> 
>>> Sent from my iDevice
>>> 
>>> On 2011-02-11, at 17:54, Robert Payne <robertpayne at me.com> wrote:
>>> 
>>>> Hey All,
>>>> 
>>>> Do MacRuby classes completely overwrite Objective-C classes if you load one in with the same class name? I'm just testing the best way to communicate to a MacRuby class from an Objective-C class and wanted to make sure.
>>>> 
>>>> Robert Payne
>>>> Interactive Developer
>>>> _______________________________________________
>>>> 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
>> _______________________________________________
>> 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
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20110212/56399785/attachment-0001.html>


More information about the MacRuby-devel mailing list