Module: Kernel
- Defined in:
- lib/RubyExt/debug.rb,
lib/RubyExt/kernel.rb
Constant Summary collapse
- STACK_TRACE_EXCLUDE =
[ /\/rspec/, /\/ruby-debug/, /\/monitor.rb/, /\/timeout.rb/, # /gems/, # /WGUI/, /\/MicroContainer/, /\/RubyExt/, /\/kernel.rb/, /\/mongrel/, /\/rack/, /\/sync/, /\/require/, /\/site_ruby/, /OpenConstructor/, ]
Instance Method Summary collapse
- #caller(int = 0) ⇒ Object
- #old_caller ⇒ Object
- #raise_without_self(*args) ⇒ Object
- #respond_to(sym, *args) ⇒ Object
-
#singleton_class(&block) ⇒ Object
def _ &b raise “Block isn’t provided!” unless b return b end.
- #where? ⇒ Boolean
Instance Method Details
#caller(int = 0) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/RubyExt/debug.rb', line 31 def caller int = 0 stack = old_caller stack = stack[(int+1)..stack.size].delete_if do |line| STACK_TRACE_EXCLUDE.any?{|re| line =~ re} end return stack end |
#old_caller ⇒ Object
30 |
# File 'lib/RubyExt/debug.rb', line 30 alias_method :old_caller, :caller |
#raise_without_self(*args) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/RubyExt/kernel.rb', line 2 def raise_without_self *args error, , the_self = nil if args.size == 1 error = RuntimeError = args[0] the_self = self elsif args.size == 2 , the_self = args error = RuntimeError elsif args.size == 3 error, , the_self = args else raise RuntimeError, "Invalid arguments!", caller end the_self = the_self.is_a?(Array) ? the_self : [the_self] list = [] the_self.each do |s| klass = (s.class == Class or s.class == Module) ? s : s.class klass.ancestors.each do |a| next if a == Object or a == Module name = a.name path = nil if RubyExt::Resource.class_exist?(name) path = RubyExt::Resource.class_to_virtual_file(name) path.sub!(".rb", "") else path = name.gsub("::", "/") end list << /#{path}/ end end stack = caller stack = stack.delete_if do |line| list.any?{|re| line =~ re} and line !~ /\/spec\// # Do not exclude Spec stacktrace. end raise error, , stack end |
#respond_to(sym, *args) ⇒ Object
43 44 45 46 |
# File 'lib/RubyExt/kernel.rb', line 43 def respond_to sym, *args return nil if not respond_to? sym send sym, *args end |
#singleton_class(&block) ⇒ Object
def _ &b raise “Block isn’t provided!” unless b return b end
53 54 55 56 57 58 59 60 |
# File 'lib/RubyExt/kernel.rb', line 53 def singleton_class(&block) if block_given? (class << self; self; end).class_eval(&block) self else (class << self; self; end) end end |
#where? ⇒ Boolean
39 40 41 42 |
# File 'lib/RubyExt/debug.rb', line 39 def where? puts "\nwhere:" puts caller end |