check contents of a pointer.

J

John Smith

Hi everyone,

I created a function pointer that points
to a method.

m.fptr = m.method( :sigm )

However.. later on I need to do an operation depending on the symbol it
is pointing at:

if m.fptr == :gam
....
elsif m.fptr == :lin
...

How do I obtain this symbol value from m.fptr?

Ted...
 
R

Rajinder Yadav

Hi everyone,

I created a function pointer that points
to a method.

m.fptr = m.method( :sigm )

However.. later on I need to do an operation depending on the symbol it
is pointing at:

if m.fptr == :gam
....
elsif m.fptr == :lin
...

How do I obtain this symbol value from m.fptr?

Ted...

try m.fptr.name
 
R

Robert Klemme

no such method :\

What version of Ruby are you using?

irb(main):001:0> RUBY_VERSION
=> "1.8.7"
irb(main):002:0> "".method:)length).name
=> "length"

irb(main):001:0> RUBY_VERSION
=> "1.9.1"
irb(main):002:0> "".method:)length).name
=> :length

Cheers

robert
 
J

John Smith

How should I get 1.9.1,
I'm using MacOS.. and tried to find
a more recent version through fink, but
I find none.


Ted.
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

How should I get 1.9.1,
I'm using MacOS.. and tried to find
a more recent version through fink, but
I find none.


Ted.
In all honesty, use rvm (http://rvm.beginrescueend.com/).

It takes a little getting used to if you aren't that familiar with Unix, but
after you figure out how it works, it is really nice. You can install all
the rubies (how I got jruby, macruby, rubinius, MRI 1.8.6, 1.8.7, 1.9.1,
1.9.2) Then it is just "$ rvm use 1.9.1" to switch to that one. Drop that in
your ~/.profile (or ~/.bash_profile if you're on Leopard) and it will always
use that version. Takes a little more work to set it up with your editor,
but not too bad for TextMate (just set an environment variable in TM, and
add 1 line to your profile)

Also lets you set up specific versions for specific projects, and even
specific sets of gems for that project, so its gems are segregated from the
rest of the system. Manages switching rubies and gems for you when you move
into and out of these project directories.
 
J

John Smith

I don't understand what you mean by "setting an environment variable in
TextMate" could you explain how you do this.. I also happen to use
Textmate for ruby.

Ted.

Josh Cheek wrote in post #954841:
 
Y

yermej

$ irb>> RUBY_VERSION

=> "1.8.6"

Then this will work:

ruby-1.8.6-p399 > "".method:)length).inspect.match(/#([^#]*)>/)[1]
=> "length"

or:

class Method
def name
inspect.match(/#([^#]*)>/)[1]
end
end

ruby-1.8.6-p399 > "".method:)length).name
=> "length"
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

I don't understand what you mean by "setting an environment variable in
TextMate" could you explain how you do this.. I also happen to use
Textmate for ruby.

Ted.
They explain how to do it in the walkthrough
http://rvm.beginrescueend.com/integration/textmate/

Starting where it says "Following that, in Textmate open up the Shell
Variables editor" with this being your goal http://cl.ly/23Yl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top