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

Making this work on a passable instance of a binding? #2

Open
markburns opened this issue Jun 12, 2017 · 3 comments
Open

Making this work on a passable instance of a binding? #2

markburns opened this issue Jun 12, 2017 · 3 comments

Comments

@markburns
Copy link

Hi, I like how concise this gem is. Just found it by looking at binding_of_caller.

One thing that doesn't work with binding_of_caller is:

require "binding_of_caller"

def determine_binding
  get_binding_from_here
end

def get_binding_from_here
  binding
end

def container_method
  called_method(determine_binding)
end

def called_method(other_binding)
  puts other_binding.of_caller(1).eval("__method__")
end

The output is container_method and not determine_binding.
I.e. the #of_caller method only acts like the current binding and not on the actual passed instance of the binding.

I'm thinking of opening an issue there, but it looks a bit unattended. So I imagine I might have to get my hands dirty.

And if I am going to do that, then maybe it's easier to start with your gem instead.

I've not really looked into the debug inspector side of things at all, so it could be that it's just not achievable.

Do you know off the top of your head if that is possible or not?

@shreeve
Copy link
Owner

shreeve commented Jun 12, 2017

@markburns - Thanks! Succinct code is always nice.

For your above scenario, there's a bit of jumping around to figure it out. What method do you want to call and what result to you expect to see?

@markburns
Copy link
Author

Sorry it's not a simple concept to explain. Or rather my explanation isn't very good.
I was trying to hint at it with the naming.
But I expect to see "determine_binding" as the output.
I.e. The method name of the caller of the passed binding. Not the method name of the caller of the current binding at evaluation time

@markburns
Copy link
Author

markburns commented Sep 6, 2018

Hey, just going through my open issues and came back to this.
I realise I was very much in the zone when understanding this problem. But after re-reading now, it took me a while to see what I meant.
So rather than this being in the spirit of chasing it up, consider this message in the spirit of giving any reader a fighting chance.

require "bindings"

def container_method
  called_method(determine_binding)
end

def called_method(other_binding)
  other_binding.of_caller(0).eval("__method__")
end

def determine_binding
  binding
end

puts container_method()
#=> called_method

# expected
#=> determine_binding

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

No branches or pull requests

2 participants