caller | -> | pp_call_stack |
Parse a caller string and break it into its components, returning an array.
Returns:
For example, from irb, require 'facet/kernel/call_stack' call_stack(1) produces [["(irb)", 2, :irb_binding], ["/usr/lib/ruby/1.8/irb/workspace.rb", 52, :irb_binding], ["/usr/lib/ruby/1.8/irb/workspace.rb", 52, nil]] Note: If the user decides to redefine caller() to output data in a different format, prior to requiring this, then the results will indeterminate. |
||
lambda | -> | fn |
A nicer shorthand for lambda/proc method.
require 'facet/kernel/fn' adder = fn { |x,y| x + y } adder[1,2] #=> 3 |
||
binding | -> | here |
A shorthand pronoun for binding().
require 'facet/kernel/here' a = 3 b = here eval( "a", b ) #=> 3 |
Raises a ScritBug error with a message.
require 'facet/kernel/bug!' if find_bug then bug! "unknown bug found" end
For debugging and showing examples. Currently this takes an argument of a string in a block.
require 'facet/kernel/demo' demo {%{ a = [1,2,3] }} demo {%{ a.slice(1,2) }} demo {%{ a.map { |x| x**3 } }}
Produces:
a = [1,2,3] #=> [1, 2, 3] a.slice(1,2) #=> [2, 3] a.map { |x| x**3 } #=> [1, 8, 27]
Random generator that returns true or false. Can also take a block that has a 50/50 chance to being executed.
requrie 'facet/kernel/maybe' maybe #=> true maybe #=> false
Require a pattern of files. This make is easy to require an entire directory, for instance.
require 'facet/kernel/require_all' require_all 'facet/time/*'
Like warn produces the current line number as well.
require 'facet/kernel/warn_with_line' warn_wtih_line("You have been warned.")
produces
3: Warning: You have been warned.
Note that this method depends on the output of caller.
Retreive the current running method. There is a lot of debate on what to call this. called differs from method_name only by the fact that it returns a symbol, rather then a string.
require 'facet/main/called' def tester; p called; end tester #=> :tester
Retreive the current running method. There is a lot of debate on what to call this. method_name differs from called only by the fact that it returns a string, rather then a symbol.
require 'facet/main/called' def tester; p method_name; end tester #=> "tester"