Sitelet https://github.com/opal/opal/pull/2132
Skip to content

Implement Native to behave like a Class - #2132

Closed
davispuh wants to merge 1 commit into
opal:masterfrom
davispuh:native
Closed

davispuh wants to merge 1 commit into
opal:masterfrom
davispuh:native

Conversation

@davispuh

Copy link
Copy Markdown
Contributor

This PR implements Native to behave both like a Module (as was before) and also like a Class which allows native objects to be extended as Ruby objects.

Consider this example

class RubyWindow < Native(`window`)
    def self.url
        location.href
    end
end

puts RubyWindow.url
# https://github.com/opal/opal/

In this way this PR also resolves #2113 and makes that #send and #method works.

@elia elia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution is interesting, but I'd like to preserve having Native inherit from BasicObject… is it possible to have a sort of Native::Kernel that will add the missing functionality when included in a Native::Object?

Comment thread opal/corelib/kernel.rb

if (!meth || meth.$$stub) {
#{raise NameError.new("undefined method `#{name}' for class `#{self.class}'", name)};
#{::Kernel.raise NameError.new("undefined method `#{name}' for class `#{self.class}'", name)};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary as #raise is also implemented by Kernel so it should be already available in this context.

@elia

elia commented Mar 24, 2021

Copy link
Copy Markdown
Member

I'm closing this as we need to find a different approach to address this issue, feel free to ping me for reopening it 👍

@elia elia closed this Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native doesn't inherit Object - very surprising

2 participants