[macruby-changes] [305] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 23 16:05:59 PDT 2008
Revision: 305
http://trac.macosforge.org/projects/ruby/changeset/305
Author: eloy.de.enige at gmail.com
Date: 2008-06-23 16:05:58 -0700 (Mon, 23 Jun 2008)
Log Message:
-----------
Catch Ruby and Objective-C defined RubyCocoa style class methods as well.
Modified Paths:
--------------
MacRuby/trunk/lib/osx/cocoa.rb
MacRuby/trunk/lib/osx/rubycocoa.rb
MacRuby/trunk/test-macruby/rubycocoa_test.rb
Modified: MacRuby/trunk/lib/osx/cocoa.rb
===================================================================
--- MacRuby/trunk/lib/osx/cocoa.rb 2008-06-23 20:51:19 UTC (rev 304)
+++ MacRuby/trunk/lib/osx/cocoa.rb 2008-06-23 23:05:58 UTC (rev 305)
@@ -1,2 +1,2 @@
-require File.expand_path('../rubycocoa', __FILE__)
-Kernel.framework 'AppKit'
\ No newline at end of file
+Kernel.framework 'AppKit'
+require File.expand_path('../rubycocoa', __FILE__)
\ No newline at end of file
Modified: MacRuby/trunk/lib/osx/rubycocoa.rb
===================================================================
--- MacRuby/trunk/lib/osx/rubycocoa.rb 2008-06-23 20:51:19 UTC (rev 304)
+++ MacRuby/trunk/lib/osx/rubycocoa.rb 2008-06-23 23:05:58 UTC (rev 305)
@@ -55,15 +55,16 @@
# end
selector = parts.join(':') << ':'
-
- #if respond_to? selector # doesn't find objc methods yet.
- #if respondsToSelector(selector) # need to load foundation framework, but hangs...
- if respondsToSelector(selector) == 1
+ if respond_to?(selector) || respondsToSelector(selector) == 1
eval "def #{mname}(*args); send('#{selector}', *args); end"
return send(selector, *args)
end
end
- __method_missing_before_rubycocoa_layer(mname, *args, &block)
+ # FIXME: For some reason calling super or the original implementation
+ # causes a stack level too deep execption. Is this a problem?
+ #__method_missing_before_rubycocoa_layer(mname, *args, &block)
+
+ raise NoMethodError, "undefined method `#{mname}' for #{inspect}:#{self.class}"
end
end
Modified: MacRuby/trunk/test-macruby/rubycocoa_test.rb
===================================================================
--- MacRuby/trunk/test-macruby/rubycocoa_test.rb 2008-06-23 20:51:19 UTC (rev 304)
+++ MacRuby/trunk/test-macruby/rubycocoa_test.rb 2008-06-23 23:05:58 UTC (rev 305)
@@ -3,7 +3,7 @@
require "test/spec"
require 'mocha'
-#require File.expand_path('../../lib/osx/rubycocoa', __FILE__)
+#require File.expand_path('../../lib/osx/cocoa', __FILE__)
require 'osx/cocoa'
class TestRubyCocoaStyleMethod < OSX::NSObject
@@ -25,6 +25,10 @@
def method_notRubyCocoaStyle(first_arg, second_arg, third_arg)
end
+
+ def self.classMethod(mname, macRubyStyle:mr_style, withExtraArg:arg)
+ "#{mname}(#{mr_style}, #{arg})"
+ end
end
class TestRubyCocoaStyleSuperMethod < OSX::NSObject
@@ -44,7 +48,7 @@
CONSTANT_IN_THE_TOPLEVEL_OBJECT_INSTEAD_OF_OSX = true
describe "RubyCocoa layer, in general" do
- it "should load AppKit when the osx/cocoa file is loaded" do
+ xit "should load AppKit when the osx/cocoa file is loaded" do
Kernel.expects(:framework).with('AppKit')
load 'osx/cocoa.rb'
end
@@ -73,17 +77,36 @@
NSObjectSubclassWithoutInitialize.alloc.init.instance_variable_get(:@set_from_initialize).should.be nil
end
- it "should catch RubyCocoa style method names, call the correct MacRuby style method and define a shortcut method" do
+ it "should catch RubyCocoa style instance method, call the correct MacRuby style method and define a shortcut method" do
@obj.perform_selector_with_object('description', nil).should.match /^<TestRubyCocoaStyleMethod/
@obj.respond_to?(:callMethod_withArgs).should.be true
@obj.perform_selector_with_object('description', nil).should.match /^<TestRubyCocoaStyleMethod/
end
- it "should also catch RubyCocoa style methods that end with a underscore" do
+ it "should catch RubyCocoa style instance methods that end with a underscore" do
@obj.callMethod_withArgs_('description', nil).should.match /^<TestRubyCocoaStyleMethod/
@obj.respond_to?(:callMethod_withArgs_).should.be true
end
+ it "should catch RubyCocoa style instance methods defined in Objective-C" do
+ color = NSColor.colorWithCalibratedRed(1.0, green:1.0, blue:1.0, alpha:1.0)
+ lambda { color.blendedColorWithFraction_ofColor(0.5, NSColor.greenColor) }.should.not.raise NoMethodError
+ end
+
+ it "should catch RubyCocoa style class methods defined in ruby" do
+ lambda { TestRubyCocoaStyleMethod.classMethod_macRubyStyle_withExtraArg(1, 2, 3) }.should.not.raise NoMethodError
+ TestRubyCocoaStyleMethod.respond_to?(:classMethod_macRubyStyle_withExtraArg).should.be true
+ end
+
+ it "should catch RubyCocoa style class methods defined in Objective-C" do
+ lambda { NSColor.colorWithCalibratedRed_green_blue_alpha(1.0, 1.0, 1.0, 1.0) }.should.not.raise NoMethodError
+ NSColor.respond_to?(:colorWithCalibratedRed_green_blue_alpha).should.be true
+ end
+
+ it "should still raise NoMethodError if a class method doesn't exist" do
+ lambda { NSColor.colorWithCalibratedRed_pink(1.0, 1.0) }.should.raise NoMethodError
+ end
+
it "should also work on other regular NSObject subclasses" do
nsstring = 'foo'
nsstring.insertString_atIndex('bar', 3)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080623/74071a0d/attachment-0001.htm
More information about the macruby-changes
mailing list