Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define method by braces #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Define method by braces #5

wants to merge 2 commits into from

Conversation

gogotanaka
Copy link
Contributor

I'm aiming to https://gist.github.com/chancancode/61f31ac0b508c8eccad7

Right now, we can write as below.

require 'java'
class MyClass
  extend JavaClass

  public int my_method(arg1, arg2) {"
    ...
  "}
end

@chancancode
Copy link
Contributor

Check out https://gist.github.com/chancancode/0087d86c935db02453ae, I think you can use some of the same tricks here so you can pass real ruby code in the block instead of string.

The drawback is you'd need binding_of_caller and use method_missing to fake the local variables (turns out you can't define new dynamic local variables in Ruby)

@gogotanaka
Copy link
Contributor Author

Wow, awesome. binding_of_caller + method_missing is really powerful..!!!
It seems we can do anything different from Ruby totally.

I'm gonna do same things. thanks.

@chancancode
Copy link
Contributor

hahaha, there are many quirks :P

Just updated the gist and fixed the follow case.. previously it couldn't tell between these two:

function x() { ... }
function(x) { ... }

Turns out you can infer it based on whether the block is attached to def x or def function. If method_missing is called without a block, it's an identifier. If it's called with a block, it's a named function.

This would probably come in handy for you cause all of your method definitions will look like someIdentifier( ... ) { }, so same rules apply – no block = identifier within the ( ... ); with block = the someIdentifier call that's defining the method.

@gogotanaka
Copy link
Contributor Author

@chancancode Hmm, it does make sense. nice idea. I'm gonna do that.

@gogotanaka
Copy link
Contributor Author

I just try to extract the code from a block by using seattlerb/ruby2rbuy and eval. but ... I couldn't do from block made dynamic.

You'er way is most reasonable after all.

@chancancode
Copy link
Contributor

I don't know about "reasonable", but it was certainly fun :P


Sent from Mailbox

On Thu, Dec 4, 2014 at 4:20 PM, Kazuki Tanaka [email protected]
wrote:

I just try to extract the code from a block by using seattlerb/ruby2rbuy and eval. but ... I couldn't do from block made dynamic.

You'er way is more reasonable after all.

Reply to this email directly or view it on GitHub:
#5 (comment)

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.

2 participants