lib/tap/support/constant.rb in bahuvrihi-tap-0.10.4 vs lib/tap/support/constant.rb in bahuvrihi-tap-0.10.5
- old
+ new
@@ -51,20 +51,32 @@
# Returns the document for require_path, if set, or nil otherwise.
def document
require_path ? Support::Lazydoc[require_path] : nil
end
+ # True if another is a Constant with the same name
+ # and require_path as self.
def ==(another)
another.kind_of?(Constant) &&
another.name == self.name &&
another.require_path == self.require_path
end
-
+
+ # Looks up and returns the constant indicated by name.
+ # If the constant cannot be found, the constantize
+ # requires require_path and tries again. Raises an
+ # NameError if the constant cannot be found.
def constantize
name.try_constantize do |const_name|
- require require_path
+ require require_path if require_path
name.constantize
end
+ end
+
+ # Returns a string like:
+ # "#<Tap::Support::Constant:object_id Const::Name (require_path)>"
+ def inspect
+ "#<#{self.class}:#{object_id} #{name}#{@require_path == nil ? "" : " (#{@require_path})"}>"
end
end
end
end
\ No newline at end of file