module Kernel

Public Class Methods

delta(v1, v2) { |v1| ... } click to toggle source

Compute the difference (delta) between two values.

When a block is given the block will be applied to both arguments. Using a block in this way allows computation against a specific field in a data set of hashes or objects.

@yield iterates over each element in the data set @yieldparam item each element in the data set

@param [Object] v1 the first value @param [Object] v2 the second value

@return [Float] positive value representing the difference

between the two parameters
# File lib/pattern_matching/functions.rb, line 53
def delta(v1, v2)
  if block_given?
    v1 = yield(v1)
    v2 = yield(v2)
  end
  return (v1 - v2).abs
end
pp_s(*objs) click to toggle source

rhaseventh.blogspot.com/2008/07/ruby-and-rails-how-to-get-pp-pretty.html

# File lib/pattern_matching/functions.rb, line 29
def pp_s(*objs)
  s = StringIO.new
  objs.each {|obj|
    PP.pp(obj, s)
  }
  s.rewind
  s.read
end
repl?() click to toggle source
# File lib/pattern_matching/functions.rb, line 11
def repl?
  return ($0 == 'irb' || $0 == 'pry' || $0 == 'script/rails' || !!($0 =~ /bin\/bundle$/))
end
safe(*args, &block) click to toggle source
# File lib/pattern_matching/functions.rb, line 16
def safe(*args, &block)
  raise ArgumentError.new('no block given') unless block_given?
  result = nil
  t = Thread.new do
    $SAFE = 3
    result = self.instance_exec(*args, &block)
  end
  t.join
  return result
end

Private Instance Methods

delta(v1, v2) { |v1| ... } click to toggle source

Compute the difference (delta) between two values.

When a block is given the block will be applied to both arguments. Using a block in this way allows computation against a specific field in a data set of hashes or objects.

@yield iterates over each element in the data set @yieldparam item each element in the data set

@param [Object] v1 the first value @param [Object] v2 the second value

@return [Float] positive value representing the difference

between the two parameters
# File lib/pattern_matching/functions.rb, line 53
def delta(v1, v2)
  if block_given?
    v1 = yield(v1)
    v2 = yield(v2)
  end
  return (v1 - v2).abs
end
pp_s(*objs) click to toggle source

rhaseventh.blogspot.com/2008/07/ruby-and-rails-how-to-get-pp-pretty.html

# File lib/pattern_matching/functions.rb, line 29
def pp_s(*objs)
  s = StringIO.new
  objs.each {|obj|
    PP.pp(obj, s)
  }
  s.rewind
  s.read
end
repl?() click to toggle source
# File lib/pattern_matching/functions.rb, line 11
def repl?
  return ($0 == 'irb' || $0 == 'pry' || $0 == 'script/rails' || !!($0 =~ /bin\/bundle$/))
end
safe(*args, &block) click to toggle source
# File lib/pattern_matching/functions.rb, line 16
def safe(*args, &block)
  raise ArgumentError.new('no block given') unless block_given?
  result = nil
  t = Thread.new do
    $SAFE = 3
    result = self.instance_exec(*args, &block)
  end
  t.join
  return result
end