Class: Object

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

Instance Method Summary collapse

Instance Method Details

#and_also(&block) ⇒ Object



11
12
13
# File 'lib/core_utilities/core_ext/object.rb', line 11

def and_also(&block)
  self && yield(self)
end

#as {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Object)

    the object that the method was called on



2
3
4
# File 'lib/core_utilities/core_ext/object.rb', line 2

def as(&block)
  yield self
end

#is_excluded_from?(*others) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/core_utilities/core_ext/object.rb', line 21

def is_excluded_from?(*others)
  others.flatten_splat.exclude?(self)
end

#is_included_in?(*others) ⇒ Boolean

Convenience methods for a more idiomatic code than [ “users”, “purchases” ].include?(controller_name) so that the same can now be written as controller_name.is_included_in?(‘users’, ‘purchases’)

Returns:

  • (Boolean)


17
18
19
# File 'lib/core_utilities/core_ext/object.rb', line 17

def is_included_in?(*others)
  others.flatten_splat.include?(self)
end

#is_one_kind_of?(*klasses) ⇒ Boolean

Similar to is_a? or kind_of? but with an array of possible classes. Returns the matching class or a nil.

Returns:

  • (Boolean)


26
27
28
# File 'lib/core_utilities/core_ext/object.rb', line 26

def is_one_kind_of?(*klasses)
  klasses.flatten_splat.detect {|klass| klass === self }
end

#or_else(&block) ⇒ Object

Logic utilities



7
8
9
# File 'lib/core_utilities/core_ext/object.rb', line 7

def or_else(&block)
  self || yield(self)
end