module Sourcify::Method::Stubs
Public Instance Methods
Returns the raw code enclosed within this method.
class MyMath def self.sum(x, y) x + y # (blah) end end MyMath.method(:sum).to_raw_source >> "def sum(x, y) >> x + y # (blah) >> end"
This works for methods defined via Module#define_method as well. Pls see to_source
for options/arguments supported.
# File lib/sourcify/lib/sourcify/method.rb, line 123 def to_raw_source(opts={}, &body_matcher) # NOTE: this is a stub for the actual one in Methods::ToRawSource end
Returns the S-expression representation of this method.
class MyMath def self.sum(x, y) x + y # (blah) end end MyMath.method(:sum).to_sexp >> s(:defn, >> :sum, >> s(:args, :x, :y), >> s(:scope, s(:block, s(:call, s(:lvar, :x), :+, s(:arglist, s(:lvar, :y))))))
This works for methods defined via Module#define_method as well. Pls see to_source
for options/arguments supported.
# File lib/sourcify/lib/sourcify/method.rb, line 102 def to_sexp(opts={}, &body_matcher) # NOTE: this is a stub for the actual one in Methods::ToSexp end
Returns the code representation of this method. Unlike Method#to_raw_source, the returned code retains only the functional aspects, fluff like comments are stripped off.
class MyMath def self.sum(x, y) x + y # (blah) end end MyMath.method(:sum).to_source # >> "def sum(x, y) # >> (x + y) # >> end"
This works for method defined via Module#define_method as well. The following approach of defining method yields exactly the same result as above:
class MyMath class << self define_method(:sum) do |x,y| x + y # (blah) end end end MyMath.method(:sum).to_source # >> "def sum(x, y) # >> (x + y) # >> end"
The following options are supported:
-
:strip_enclosure
when set to true, strips the method enclosure to get just the meat within.MyMath.method(:sum).to_source(:strip_enclosure => true) # >> "(x + y)"
-
:attached_to
is useful ONLY when a method is defined via Module#define_method, pls seeSourcify::Proc::Stubs#to_source
for more info. -
:ignore_nested
is useful ONLY when a method is defined via Module#define_method, pls seeSourcify::Proc::Stubs#to_source
for more info. -
an optional
body_matcher
block is supported as well, again this is ONLY useful for method defined via Module#define_method, pls seeSourcify::Proc::Stubs#to_source
for more info.
# File lib/sourcify/lib/sourcify/method.rb, line 80 def to_source(opts={}, &body_matcher) # NOTE: this is a stub for the actual one in Methods::ToSource end