Class: Object

Inherits:
BasicObject
Defined in:
lib/winexcel/core_ext/object.rb

Instance Method Summary collapse

Instance Method Details

#eq?(obj) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/winexcel/core_ext/object.rb', line 30

def eq?(obj)
  return self.to_s.upcase == obj.to_s.upcase
end

#has?(obj) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/winexcel/core_ext/object.rb', line 22

def has?(obj)
  if [nil].include?(self)
    return false
  else
    return self.include?(obj)
  end
end

#in?(arr) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/winexcel/core_ext/object.rb', line 18

def in?(arr)
  return true if arr.unempty? and arr.include?(self)
end

#unempty?Boolean

Returns true if the object is nil or empty. It works on most popular objects like hashes, arrays and strings. Main purpose is to avoid double checking statements (and to eliminate bugs caused by single checking) like in code below:

if some_obj == nil or some_obj.empty?
  # do something
end

Remarks: When this funcion is applied to a String, false is returned when

the string contains white space characters only.

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/winexcel/core_ext/object.rb', line 10

def unempty?
  if [nil, [], {}].include?(self) or (self.kind_of?(String) and self.strip == '')
    return false
  else
    return true
  end
end