hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It’s especailly useful when you examine other’s code
or dynamic generating func/method.
On 06-09-01, at 02:45, femto gary wrote:
hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It’s especailly useful when you examine other’s code
or dynamic generating func/method.
No, there are only a few languages I can think of (okay, 2) that
allow this: the aforementioned javascript, and Io; Ruby does not.
femto gary wrote:
hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It’s especailly useful when you examine other’s code
or dynamic generating func/method.
you can search c.l.ruby for all the SCRIPT_LINES__ tricks that people
ahve done
On Sep 1, 2006, at 12:23 AM, Jeremy T. wrote:
On 06-09-01, at 02:45, femto gary wrote:
hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It’s especailly useful when you examine other’s code
or dynamic generating func/method.No, there are only a few languages I can think of (okay, 2) that
allow this: the aforementioned javascript, and Io; Ruby does not.
Lies (provided the method is written in Ruby).
$ ruby -rlib/ruby2ruby.rb -I …/…/ruby_to_c/dev/lib/ -e ‘puts
Object.source(:source)’
def source(method_name = nil)
RubyToRuby.new.process(parse_tree(method_name))
end
You can find ruby2ruby.rb in the ZenHacks gem.
–
Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
On 01.09.2006 09:23, Jeremy T. wrote:
this: the aforementioned javascript, and Io; Ruby does not.
Just out of curiosity: what about Lisp?
robert
hi,
On 9/1/06, femto gary [email protected] wrote:
hello all, Can I see method source code,
like in javascript, when you generate a function,
you can call to_string on it to see its source code.
It’s especailly useful when you examine other’s code
or dynamic generating func/method.
http://blog.zenspider.com/archives/2005/02/rubytoruby.html
may be of some use
hello all, Can I see method source code,
http://blog.zenspider.com/archives/2005/02/rubytoruby.html
Yup. I made another, much simpler one, using method_added:
http://svn.twifkak.com/jonx/site_ruby/dlm/irb.rb
Only works for methods defined normally, in actual files. Not
meta-programming friendly or anything. Just a cheap hack, but great (as
the URL implies) for IRB use.
Devin
On 06-09-01, at 04:10, Robert K. wrote:
Just out of curiosity: what about Lisp?
I don’t know of a single lisp implementation that lets you do this,
perhaps you could enlighten me?
On 01.09.2006 11:26, Jeremy T. wrote:
No, there are only a few languages I can think of (okay, 2) that
allow this: the aforementioned javascript, and Io; Ruby does not.Just out of curiosity: what about Lisp?
I don’t know of a single lisp implementation that lets you do this,
perhaps you could enlighten me?
No LISP guru here
I probably confused lambdas with normal functions:
[1]> (setq f1 (lambda (x) (+ x x)))
#<FUNCTION :LAMBDA (X) (+ X X)>
[2]> (funcall f1 10)
20
[3]> f1
#<FUNCTION :LAMBDA (X) (+ X X)>
So, for a lambda you can - but apparently for functions you can’t. Or
can you?
Kind regards
robert
On 9/1/06, Robert K. [email protected] wrote:
So, for a lambda you can - but apparently for functions you can’t. Or
can you?
I think that it just looks like the source here. The print-name of a
lambda can look pretty much like source code because the internal
representation looks a lot like the source code. But it’s not really
the source code.
–
Rick DeNatale
My blog on Ruby
http://talklikeaduck.denhaven2.com/
IPMS/USA Region 12 Coordinator
http://ipmsr12.denhaven2.com/
Visit the Project Mercury Wiki Site
http://www.mercuryspacecraft.com/
On Sep 2, 2006, at 5:28 PM, Rick DeNatale wrote:
[3]> f1
Note that this is the same reason Ruby2Ruby doesn’t give you the
“source code”. Of course the OP probably doesn’t really care if he
gets the source code “character for character”.
Rick DeNatale wrote:
[3]> f1
#<FUNCTION :LAMBDA (X) (+ X X)>So, for a lambda you can - but apparently for functions you can’t. Or
can you?I think that it just looks like the source here. The print-name of a
lambda can look pretty much like source code because the internal
representation looks a lot like the source code. But it’s not really
the source code.
And what about Forth ? At least the HP48 version can show
source, and it’s easy to implement in a “personal” version.