Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4079032
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:44:57+00:00 2026-05-20T17:44:57+00:00

I have a new MacRuby application. I’m trying to call a MacRuby method from

  • 0

I have a new MacRuby application. I’m trying to call a MacRuby method from JavaScript loaded in a webView within the application.

The Calling Objective-C Methods From JavaScript tutorial shows how to add a key to the webScriptObject that’s value is an Objective-C object. Thus you can call Obj-C methods from JavaScript.

Unfortunately this does not work with MacRuby classes/methods. Below is a shorten version of my WebView’s loadDelegate:

class WebLoadDelegate

attr_accessor :objc_bridge, :mr_bridge

def webView(sender, windowScriptObjectAvailable:windowScriptObject)
    scriptObject = windowScriptObject

    self.mr_bridge = MacRubyBridge.new();
    self.objc_bridge = JavaScriptBridge.instance();

    scriptObject.setValue(self.objc_bridge, forKey:"ObjCInstance")
    scriptObject.setValue(self.mr_bridge, forKey:"MacRubyInstance")
end

end

When the webScriptObject is available i add two keys to it: ObjCInstance and MacRubyInstance.

Here’s the implementation of the ObjC class:

#import "JavaScriptBridge.h"

static JavaScriptBridge *gInstance = NULL;

@implementation JavaScriptBridge

+ (JavaScriptBridge *)instance {
    gInstance = [[self alloc] init];

    return gInstance;
}

+ (NSString *) webScriptNameForSelector:(SEL)sel
{       
    return @"nameAtIndex";
}

+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
{
    if (aSelector == @selector(nameAtIndex:)) return NO;
    return YES;
}

- (NSString *)nameAtIndex:(int)index {
    return @"works";
}


@end

And here’s what’s supposed to be the same thing in Ruby:

class MacRubyBridge

    def nameAtIndex(i)
        return "fails"
    end

    def self.webScriptNameForSelector(sel)
        return "nameAtIndex";
    end


    def self.isSelectorExcludedFromWebScript(sel)
        if (sel == :nameAtIndex) 
            false
        else
            true
        end
    end

end

The only problem is the Objective-C implementation works fine. On the JS side you can call:

window.ObjCInstance.nameAtIndex_(1) 

Which returns the string “works”.

But the MacRuby implementation fails. When you call:

window.MacRubyInstance.nameAtIndex_(1) 

You get:

Result of expression ‘window.MacRubyInstance.nameAtIndex_’ [undefined] is not a function

The webScriptNameForSelector and isSelectorExcludedFromWebScript methods never get called on the MacRuby implementation. I think that’s the problem, but I don’t know why they aren’t getting called.

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:44:58+00:00Added an answer on May 20, 2026 at 5:44 pm

    I showed how to do that in this tutorial/blog post.

    My guess is that in your case, the following code is the problem:

        def self.isSelectorExcludedFromWebScript(sel)
         if (sel == :nameAtIndex) 
             false
         else
            true
         end
       end
    

    The selector sent as an argument is more than likely not equal to the symbol your put. Try to return false for all and see if that works. Try:

    def self.isSelectorExcludedFromWebScript(sel); false end
    

    Also, hopefully my example will help you fix this issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have new problem. My code: .method public static void Main() cil managed {
I have my new macbook air. I have created one test application. now i
I have new to python and django I am creating poll application and in
From my last question , I have new idea for database protection. The following
I have updated our project from svn and I have new migration files. When
I have new problem. I need to make returntype parameter free method with list
I'd like to refresh a div. It should have new information from the server
i have new webcam. The software of the webcam can give out the webcam
When we have new in C#, that personally I see only as a workaround
What is the use of malloc and free when we have new and delete

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.