Class: Object

Inherits:
BasicObject
Defined in:
lib/hash-utils/object.rb

Overview

Object extension.

Constant Summary collapse

@@__hash_utils_methods_index =
{ }
@@__hash_utils_object_index =
[ ]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.__hash_utils_instance_respond_to?(call) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hash-utils/object.rb', line 44

def self.__hash_utils_instance_respond_to?(call)
    if not @@__hash_utils_methods_index.has_key? self
        instance_methods = self.instance_methods
      
        if Ruby::Version >= [1, 9]
            require "set"
            @@__hash_utils_methods_index[self] = Set::new(instance_methods)
            
            if self != Object
                @@__hash_utils_methods_index[self] -= @@__hash_utils_object_index
            end
        else
            @@__hash_utils_methods_index[self] = { }
            _col = @@__hash_utils_methods_index[self]
            
            instance_methods.each do |i|
                _col[i] = true
            end
            
            if self != Object
                @@__hash_utils_object_index.each do |i|
                    _col.delete(i)
                end
            end
        end
    end
    
    @@__hash_utils_methods_index[self].include? call
end

Instance Method Details

#**(count) ⇒ Object



168
169
170
171
172
# File 'lib/hash-utils/object.rb', line 168

def **(count)
    result = [ ]
    count.times { result << self.dup }
    return result
end

#array?Boolean

Returns:

  • (Boolean)


287
288
289
# File 'lib/hash-utils/object.rb', line 287

def array?
    self.kind_of? Array
end

#boolean?Boolean

Returns:

  • (Boolean)


274
275
276
# File 'lib/hash-utils/object.rb', line 274

def boolean?
    self.true? or self.false?
end

#enumerable?Boolean

Returns:

  • (Boolean)


313
314
315
# File 'lib/hash-utils/object.rb', line 313

def enumerable?
    self.kind_of? Enumerable
end

#false?Boolean

Returns:

  • (Boolean)


209
210
211
# File 'lib/hash-utils/object.rb', line 209

def false?
    self.kind_of? FalseClass
end

#hash?Boolean

Returns:

  • (Boolean)


300
301
302
# File 'lib/hash-utils/object.rb', line 300

def hash?
    self.kind_of? Hash
end

#in?(range) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/hash-utils/object.rb', line 141

def in?(range)
    range.include? self
end

#instance_of_any?(*classes) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/hash-utils/object.rb', line 87

def instance_of_any?(*classes)
    if classes.first.array?
        classes = classes.first
    end
    
    classes.each do |cls|
        if self.instance_of? cls
            return true
        end
    end
    
    return false
end

#io?Boolean

Returns:

  • (Boolean)


183
184
185
# File 'lib/hash-utils/object.rb', line 183

def io?
    false
end

#kind_of_any?(*classes) ⇒ Boolean Also known as: is_a_any?

Returns:

  • (Boolean)


113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/hash-utils/object.rb', line 113

def kind_of_any?(*classes)
    if classes.first.array?
        classes = classes.first
    end
    
    classes.each do |cls|
        if self.kind_of? cls
            return true
        end
    end
    
    return false
end

#number?Boolean

Returns:

  • (Boolean)


261
262
263
# File 'lib/hash-utils/object.rb', line 261

def number?
    self.kind_of? Numeric
end

#proc?Boolean

Returns:

  • (Boolean)


248
249
250
# File 'lib/hash-utils/object.rb', line 248

def proc?
    self.kind_of? Proc
end

#string?Boolean

Returns:

  • (Boolean)


222
223
224
# File 'lib/hash-utils/object.rb', line 222

def string?
    self.kind_of? String
end

#symbol?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/hash-utils/object.rb', line 235

def symbol?
    self.kind_of? Symbol
end

#to_bObject



154
155
156
# File 'lib/hash-utils/object.rb', line 154

def to_b
    !!self
end

#to_symbolObject Also known as: to_sym



328
329
330
# File 'lib/hash-utils/object.rb', line 328

def to_symbol
    self.to_s.to_sym
end

#true?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/hash-utils/object.rb', line 196

def true?
    self.kind_of? TrueClass
end