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

Object Additions

Kyanite definitions

Object, KKernel

Kyanite tests and examples

TestKyaniteObject

Usage

require 'kyanite/basics'

Instance Method Summary (collapse)

Instance Method Details

- (false) blank?

Returns false

Returns:

  • (false)


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

def blank? 
    false
end

- (Object) deep_copy

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

- (false) empty?

Returns false

Returns:

  • (false)


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

def empty? 
    false
end

- (false) is_collection?

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

- (Boolean) is_numeric?

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

- (Object) name_of_constant(wert_der_konstanten)

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

- (Object) repeat_n_seconds(n = 1, &block) Originally defined in module KKernel

Repeats a block until the time is up. Returns the number of passes. All Exceptions are caught (=> bad blocks seem to run faster). Example (using Numeric):

3.seconds do
 puts Time.now.inspect
end

Example (using KKernel):

repeat_n_seconds 3 do
 puts Time.now.inspect
end

- (Object) respond(sym, *args)

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

- (Object) silence_warnings Originally defined in module KKernel

Silence all Ruby warnings for the following block. Useful to override constants. Example:

TEST = 1
silence_warnings do
 TEST = 2
end

- (Set) to_set

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