Module: Kernel

Defined in:
lib/dolzenko/core_ext/kernel/r.rb,
lib/dolzenko/core_ext/kernel/in.rb,
lib/dolzenko/core_ext/kernel/ergo.rb

Instance Method Summary collapse

Instance Method Details

#ergo(&b) ⇒ Object

Yield self -or- return self.

"a".ergo.upcase #=> "A"
nil.ergo.foobar #=> nil

"a".ergo{ |o| o.upcase } #=> "A"
nil.ergo{ |o| o.foobar } #=> nil

This is like #tap, but tap yields self -and- returns self.

CREDIT: Daniel DeLorme



15
16
17
18
19
20
21
# File 'lib/dolzenko/core_ext/kernel/ergo.rb', line 15

def ergo &b
  if block_given?
    b.arity == 1 ? yield(self) : instance_eval(&b)
  else
    self
  end
end

#in?(arrayish, *more) ⇒ Boolean

Is self included in other?

5.in?(0..10)       #=> true
5.in?([0,1,2,3])   #=> false

Returns:

  • (Boolean)


7
8
9
10
# File 'lib/dolzenko/core_ext/kernel/in.rb', line 7

def in?(arrayish, *more)
  arrayish = more.unshift(arrayish) unless more.empty?
  arrayish.include?(self)
end

#r(*args) ⇒ Object

‘puts` for web application debugging



3
4
5
# File 'lib/dolzenko/core_ext/kernel/r.rb', line 3

def r(*args)
  raise (args.size == 1 ? args[0] : args).inspect
end