Class: Object

Inherits:
BasicObject
Defined in:
lib/card/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#deep_cloneObject

FIXME: move this, mixin, don’t extend Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/card/core_ext.rb', line 3

def deep_clone
  case self
  when Fixnum, Bignum, Float, NilClass, FalseClass, TrueClass, Symbol
    klone = self
  when Hash
    klone = clone
    each { |k, v| klone[k] = v.deep_clone }
  when Array
    klone = clone
    klone.clear
    each { |v| klone << v.deep_clone }
  else
    klone = clone
  end
  klone.instance_variables.each do |v|
    klone.instance_variable_set(v,
                                klone.instance_variable_get(v).deep_clone)
  end
  klone
end

#send_if(method, *args, &_block) ⇒ Object



28
29
30
# File 'lib/card/core_ext.rb', line 28

def send_if     method, *args, &_block
  (block_given? ? yield : self) && send(method, *args)
end

#send_unless(method, *args, &_block) ⇒ Object



24
25
26
# File 'lib/card/core_ext.rb', line 24

def send_unless method, *args, &_block
  (block_given? ? yield : self) || send(method, *args)
end

#to_nameObject



32
33
34
# File 'lib/card/core_ext.rb', line 32

def to_name
  Card::Name.new self
end

#to_viewnameObject



36
37
38
# File 'lib/card/core_ext.rb', line 36

def to_viewname
  Card::ViewName.new self
end