Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/smklib/object_ext.rb
Class Method Summary collapse
Instance Method Summary collapse
- #deep_clone ⇒ Object
- #ignore_exception(*exceptions, &block) ⇒ Object
- #in?(array) ⇒ Boolean
- #to_class ⇒ Object
Class Method Details
.run_once(unique_string, &block) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/smklib/object_ext.rb', line 3 def self.run_once(unique_string, &block) $run_once_guard ||= {} return if $run_once_guard[unique_string] raise "No block given" unless block_given? yield $run_once_guard[unique_string] = true end |
Instance Method Details
#deep_clone ⇒ Object
20 21 22 |
# File 'lib/smklib/object_ext.rb', line 20 def deep_clone Marshal::load(Marshal.dump(self)) end |
#ignore_exception(*exceptions, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/smklib/object_ext.rb', line 24 def ignore_exception(*exceptions, &block) begin yield rescue Exception => e skip = false exceptions.each { |ex| skip = true if e.kind_of? ex } raise e unless skip end end |
#in?(array) ⇒ Boolean
15 16 17 |
# File 'lib/smklib/object_ext.rb', line 15 def in?(array) array.include? self end |
#to_class ⇒ Object
11 12 13 |
# File 'lib/smklib/object_ext.rb', line 11 def to_class self.class.const_get self.to_s end |