Module: Kernel

Defined in:
lib/r_kit/grid/kernel_extend.rb,
lib/r_kit/utility/kernel_extend.rb,
lib/r_kit/backtrace/kernel_extend.rb

Instance Method Summary collapse

Instance Method Details

#__class__Object



3
4
5
# File 'lib/r_kit/utility/kernel_extend.rb', line 3

def __class__
  self.class
end

#__namespace__Object



7
8
9
# File 'lib/r_kit/utility/kernel_extend.rb', line 7

def __namespace__
  (__class__.name.deconstantize.presence || 'Object').constantize
end

#_backtrace_from_continuation(&block) ⇒ Object Also known as: backtrace



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/r_kit/backtrace/kernel_extend.rb', line 21

def _backtrace_from_continuation &block
  cc = nil
  block ||= ->(obj){ obj != self }

  tracer = TracePoint.trace(:return) do |tp|
    if tp.self != self && block.call(tp.self)
      tracer.disable
      cc.call tp.self
    end
  end

  backtrace = callcc { |cont| cc = cont }
  backtrace unless backtrace.is_a? Continuation
end

#_backtrace_from_ruby_vm(&block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/r_kit/backtrace/kernel_extend.rb', line 3

def _backtrace_from_ruby_vm &block
  stack_level = 0
  block ||= ->(obj){ obj != self }

  RubyVM::DebugInspector.open do |inspector|
    loop do
      stack_binding = begin
        inspector.frame_binding(stack_level += 1)
      rescue ArgumentError
        nil
      end

      obj = stack_binding.try :eval, 'self'
      return obj if obj != self && block.call(obj)
    end
  end
end

#Grid(object, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/r_kit/grid/kernel_extend.rb', line 3

def Grid object, &block

  if object.kind_of? RKit::Grid::Base
    object
  elsif object.respond_to? :to_grid
    object.to_grid &block
  else
    RKit::Grid::Base::Grid.new Array.wrap(object), &block
  end

end

#running_scriptObject



12
13
14
# File 'lib/r_kit/utility/kernel_extend.rb', line 12

def running_script
  "#{ File.basename($0) } #{ ARGV.join " " }"
end

#running_script?(script) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/r_kit/utility/kernel_extend.rb', line 16

def running_script? script
  Regexp.new(script) =~ running_script
end