Sha256: bb9cc3ccacbe4611594ccef7d74dae179039f91543eae52e89e8a7f63141ac3c

Contents?: true

Size: 1.38 KB

Versions: 24

Compression:

Stored size: 1.38 KB

Contents

# encoding: utf-8

# Object
class Object
  # Check boolean type
  #
  #   boolean? true # => true
  #   boolean? false # => true
  #   boolean? nil # => false
  #   boolean? 'true' # => false
  #   boolean? 'false' # => false
  #   boolean? '' # => false
  def boolean?
    self.is_a?(TrueClass) || self.is_a?(FalseClass)
  end

  # Get self define methods.
  #
  #   class SampleClass < String
  #     def public_hello
  #       "public hello"
  #     end
  #
  #     protected
  #
  #     def protected_hello
  #       "protected hello"
  #     end
  #
  #     private
  #
  #     def private_hello
  #       "private hello"
  #     end
  #   end
  #
  #   SampleClass.new.my_methods # => [:public_hello, :protected_hello, :private_hello]
  def my_methods
    public_methods(false) + protected_methods(false) + private_methods(false)
  end

  # If self match any one of args, return true.
  #
  #   "hoge".any_of? %w{hoge hige} # => true
  #   "hige".any_of? %w{hoge hige} # => true
  #   "hege".any_of? %w{hoge hige} # => false
  def any_of?(*args)
    args.each { |value|return true if self == value }
    false
  end

  # you get bool value
  #
  #   true.to_bool # => true
  #   false.to_bool # => false
  #   0.to_bool # => true
  #   1.to_bool # => true
  #   ''.to_bool # => true
  #   'true'.to_bool # => true
  #   'false'.to_bool # => true
  #   nil.to_bool # => false
  def to_bool
    !!self
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.40 lib/open_classes/object.rb
tbpgr_utils-0.0.39 lib/open_classes/object.rb
tbpgr_utils-0.0.38 lib/open_classes/object.rb
tbpgr_utils-0.0.37 lib/open_classes/object.rb
tbpgr_utils-0.0.36 lib/open_classes/object.rb
tbpgr_utils-0.0.35 lib/open_classes/object.rb
tbpgr_utils-0.0.34 lib/open_classes/object.rb
tbpgr_utils-0.0.33 lib/open_classes/object.rb
tbpgr_utils-0.0.32 lib/open_classes/object.rb
tbpgr_utils-0.0.31 lib/open_classes/object.rb
tbpgr_utils-0.0.30 lib/open_classes/object.rb
tbpgr_utils-0.0.29 lib/open_classes/object.rb
tbpgr_utils-0.0.28 lib/open_classes/object.rb
tbpgr_utils-0.0.27 lib/open_classes/object.rb
tbpgr_utils-0.0.26 lib/open_classes/object.rb
tbpgr_utils-0.0.25 lib/open_classes/object.rb
tbpgr_utils-0.0.24 lib/open_classes/object.rb
tbpgr_utils-0.0.23 lib/open_classes/object.rb
tbpgr_utils-0.0.22 lib/open_classes/object.rb
tbpgr_utils-0.0.21 lib/open_classes/object.rb