lib/hanami/utils/basic_object.rb in hanami-utils-2.0.0.alpha1 vs lib/hanami/utils/basic_object.rb in hanami-utils-2.0.0.alpha2

- old
+ new

@@ -4,12 +4,29 @@ module Utils # BasicObject # # @since 0.3.5 class BasicObject < ::BasicObject - # Return the class for debugging purposes. + # Lookups constants at the top-level namespace, if they are missing in the + # current context. # + # @param name [Symbol] the constant name + # + # @return [Object, Module] the constant + # + # @raise [NameError] if the constant cannot be found + # + # @since 1.3.4 + # @api private + # + # @see https://ruby-doc.org/core/Module.html#method-i-const_missing + def self.const_missing(name) + ::Object.const_get(name) + end + + # Returns the class for debugging purposes. + # # @since 0.3.5 # # @see http://ruby-doc.org/core/Object.html#method-i-class def class (class << self; self; end).superclass @@ -21,16 +38,59 @@ # # @since 0.3.5 # # @see http://ruby-doc.org/core/Object.html#method-i-inspect # - # rubocop:disable Style/FormatString # rubocop:disable Style/FormatStringToken def inspect "#<#{self.class}:#{'0x0000%x' % (__id__ << 1)}#{__inspect}>" end # rubocop:enable Style/FormatStringToken - # rubocop:enable Style/FormatString + + # @!macro [attach] instance_of?(class) + # + # Determines if self is an instance of given class or module + # + # @param class [Class,Module] the class of module to verify + # + # @return [TrueClass,FalseClass] the result of the check + # + # @raise [TypeError] if the given argument is not of the expected types + # + # @since 1.3.2 + # + # @see http://ruby-doc.org/core/Object.html#method-i-instance_of-3F + define_method :instance_of?, ::Object.instance_method(:instance_of?) + + # @!macro [attach] is_a?(class) + # + # Determines if self is of the type of the object class or module + # + # @param class [Class,Module] the class of module to verify + # + # @return [TrueClass,FalseClass] the result of the check + # + # @raise [TypeError] if the given argument is not of the expected types + # + # @since 1.3.2 + # + # @see http://ruby-doc.org/core/Object.html#method-i-is_a-3F + define_method :is_a?, ::Object.instance_method(:is_a?) + + # @!macro [attach] kind_of?(class) + # + # Determines if self is of the kind of the object class or module + # + # @param class [Class,Module] the class of module to verify + # + # @return [TrueClass,FalseClass] the result of the check + # + # @raise [TypeError] if the given argument is not of the expected types + # + # @since 1.3.2 + # + # @see http://ruby-doc.org/core/Object.html#method-i-kind_of-3F + define_method :kind_of?, ::Object.instance_method(:kind_of?) # Alias for __id__ # # @return [Fixnum] the object id #