Class: Object

Inherits:
BasicObject
Includes:
KKernel
Defined in:
lib/kyanite/general/object.rb,
lib/kyanite/set.rb,
lib/kyanite/general/kernel.rb,
lib/kyanite/enumerable/structure.rb

Overview

Object Additions

Kyanite definitions

Object, KKernel

Kyanite tests and examples

TestKyaniteObject

Usage

require ‘kyanite/basics’

Instance Method Summary collapse

Methods included from KKernel

#repeat_n_seconds, #silence_warnings

Instance Method Details

#blank?false

Returns false

Returns:

  • (false)


15
16
17
# File 'lib/kyanite/general/object.rb', line 15

def blank? 
    false
end

#deep_copyObject

Slow but in-depth alternative to dup. Also duplicates sub-objects. Is e.g. for undo operations used, see module Undoable.



30
31
32
# File 'lib/kyanite/general/object.rb', line 30

def deep_copy
  Marshal.load( Marshal.dump( self ) )
end

#empty?false

Returns false

Returns:

  • (false)


46
47
48
# File 'lib/kyanite/general/object.rb', line 46

def empty? 
    false
end

#is_collection?false

false

– Defined for all objects: Do I contain multiple objects? String and Range are not considered as collection.

Tests and examples here.

Returns:

  • (false)


26
# File 'lib/kyanite/enumerable/structure.rb', line 26

def is_collection?;                 false;          end

#is_numeric?Boolean

Is the object numeric? Tests see here.

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/kyanite/general/object.rb', line 38

def is_numeric?
  Float self 
rescue #Exception => e
  false 
end

#name_of_constant(wert_der_konstanten) ⇒ Object

Findet den Namen einer Ruby-Konstanten anhand seines Wertes. Funktioniert so nicht. Seltsamersweise funktioniert es aber, wenn man den Quelltext dieser Methode direkt ausführt. Verwendet in der Info-Ansicht des Scaffoldings.



57
58
59
# File 'lib/kyanite/general/object.rb', line 57

def name_of_constant(wert_der_konstanten)
  Object.constants.find { |c| Object.const_get(c) == wert_der_konstanten}
end

#respond(sym, *args) ⇒ Object

Like respond_to? but returns the result of the call if it does indeed respond. See Facets Kernel#respond.



23
24
25
26
# File 'lib/kyanite/general/object.rb', line 23

def respond(sym, *args)
  return nil if not respond_to?(sym)
  send(sym, *args)
end

#to_setSet

Returns Set with one element

Returns:

  • (Set)

    with one element



205
# File 'lib/kyanite/set.rb', line 205

def to_set; Set.new([self]); end