Parent

Object

Public Instance Methods

blank?() click to toggle source

Returns true if the object is nil or empty (if applicable)

  [].blank?         #=>  true
  [1].blank?        #=>  false
  [nil].blank?      #=>  false

@return [TrueClass, FalseClass]

@api public

    # File lib/extlib/blank.rb, line 12
12:   def blank?
13:     nil? || (respond_to?(:empty?) && empty?)
14:   end
full_const_get(name) click to toggle source

@param name The name of the constant to get, e.g. “Merb::Router”.

@return [Object] The constant corresponding to the name.

    # File lib/extlib/object.rb, line 67
67:   def full_const_get(name)
68:     list = name.split("::")
69:     list.shift if list.first.blank?
70:     obj = self
71:     list.each do |x|
72:       # This is required because const_get tries to look for constants in the
73:       # ancestor chain, but we only want constants that are HERE
74:       obj = obj.const_defined?(x) ? obj.const_get(x) : obj.const_missing(x)
75:     end
76:     obj
77:   end
full_const_set(name, value) click to toggle source

@param name The name of the constant to get, e.g. “Merb::Router”. @param value The value to assign to the constant.

@return [Object] The constant corresponding to the name.

    # File lib/extlib/object.rb, line 83
83:   def full_const_set(name, value)
84:     list = name.split("::")
85:     toplevel = list.first.blank?
86:     list.shift if toplevel
87:     last = list.pop
88:     obj = list.empty? ? Object : Object.full_const_get(list.join("::"))
89:     obj.const_set(last, value) if obj && !obj.const_defined?(last)
90:   end
in?(arrayish,*more) click to toggle source

@param arrayish<#> Container to check, to see if it includes the object.

@param *more

additional args, will be flattened into arrayish

@return [Boolean]

  True if the object is included in arrayish (+ more)

@example 1.in?([1,2,3]) #=> true @example 1.in?(1,2,3) #=> true

     # File lib/extlib/object.rb, line 163
163:   def in?(arrayish,*more)
164:     arrayish = more.unshift(arrayish) unless more.empty?
165:     arrayish.include?(self)
166:   end
inner_html() click to toggle source

Get the inner_html of the REXML node.

     # File lib/extlib/hash.rb, line 406
406:   def inner_html
407:     @children.join
408:   end
instance_variable_defined?(variable) click to toggle source
     # File lib/extlib/object.rb, line 174
174:     def instance_variable_defined?(variable)
175:       instance_variables.include?(variable.to_s)
176:     end
make_module(string) click to toggle source

Defines module from a string name (e.g. Foo::Bar::Baz) If module already exists, no exception raised.

@param name The name of the full module name to make

@return [nil]

     # File lib/extlib/object.rb, line 98
 98:   def make_module(string)
 99:     current_module = self
100:     string.split('::').each do |part|
101:       current_module = if current_module.const_defined?(part)
102:         current_module.const_get(part)
103:       else
104:         current_module.const_set(part, Module.new)
105:       end
106:     end
107:     current_module
108:   end
meta_class() click to toggle source

Extracts the singleton class, so that metaprogramming can be done on it.

@return [Class] The meta class.

@example [Setup]

  class MyString < String; end

  MyString.instance_eval do
    define_method :foo do
      puts self
    end
  end

  MyString.meta_class.instance_eval do
    define_method :bar do
      puts self
    end
  end

  def String.add_meta_var(var)
    self.meta_class.instance_eval do
      define_method var do
        puts "HELLO"
      end
    end
  end

@example

  MyString.new("Hello").foo #=> "Hello"

@example

  MyString.new("Hello").bar
    #=> NoMethodError: undefined method `bar' for "Hello":MyString

@example

  MyString.foo
    #=> NoMethodError: undefined method `foo' for MyString:Class

@example

  MyString.bar
    #=> MyString

@example

  String.bar
    #=> NoMethodError: undefined method `bar' for String:Class

@example

  MyString.add_meta_var(:x)
  MyString.x #=> HELLO

@details [Description of Examples]

  As you can see, using #meta_class allows you to execute code (and here,
  define a method) on the metaclass itself. It also allows you to define
  class methods that can be run on subclasses, and then be able to execute
  code on the metaclass of the subclass (here MyString).

  In this case, we were able to define a class method (add_meta_var) on
  String that was executable by the MyString subclass. It was then able to
  define a method on the subclass by adding it to the MyString metaclass.

  For more information, you can check out _why's excellent article at:
  http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
    # File lib/extlib/object.rb, line 62
62:   def meta_class() class << self; self end end
quacks_like?(duck) click to toggle source

@param duck<Symbol, Class, Array> The thing to compare the object to.

@note

  The behavior of the method depends on the type of duck as follows:
  Symbol:: Check whether the object respond_to?(duck).
  Class:: Check whether the object is_a?(duck).
  Array::
    Check whether the object quacks_like? at least one of the options in the
    array.

@return [Boolean]

  True if the object quacks like duck.
     # File lib/extlib/object.rb, line 122
122:   def quacks_like?(duck)
123:     case duck
124:     when Symbol
125:       self.respond_to?(duck)
126:     when Class
127:       self.is_a?(duck)
128:     when Array
129:       duck.any? {|d| self.quacks_like?(d) }
130:     else
131:       false
132:     end
133:   end
to_html() click to toggle source

Converts the node into a readable HTML node.

@return [String] The HTML node in text form.

     # File lib/extlib/hash.rb, line 413
413:   def to_html
414:     attributes.merge!(:type => @type ) if @type
415:     "<#{name}#{attributes.to_xml_attributes}>#{@nil_element ? '' : inner_html}</#{name}>"
416:   end
to_s() click to toggle source

@alias # #

     # File lib/extlib/hash.rb, line 419
419:   def to_s
420:     to_html
421:   end
translate_xml_entities(value) click to toggle source

Convert basic XML entities into their literal values.

@param value<#> An XML fragment.

@return [#] The XML fragment after converting entities.

     # File lib/extlib/hash.rb, line 389
389:   def translate_xml_entities(value)
390:     value.gsub(/&lt;/,   "<").
391:           gsub(/&gt;/,   ">").
392:           gsub(/&quot;/, '"').
393:           gsub(/&apos;/, "'").
394:           gsub(/&amp;/,  "&")
395:   end
try_call(*args) click to toggle source

If receiver is callable, calls it and returns result. If not, just returns receiver itself

@return [Object]

     # File lib/extlib/object.rb, line 147
147:   def try_call(*args)
148:     if self.respond_to?(:call)
149:       self.call(*args)
150:     else
151:       self
152:     end
153:   end
try_dup() click to toggle source

Override this in a child if it cannot be dup’ed

@return [Object]

     # File lib/extlib/object.rb, line 138
138:   def try_dup
139:     self.dup
140:   end
try_dup() click to toggle source

Override this in a child if it cannot be dup’ed

@return [Object]

   # File lib/extlib/try_dup.rb, line 5
5:   def try_dup
6:     self.dup
7:   end
typecast_value(value) click to toggle source

Typecasts a value based upon its type. For instance, if node has # == “integer”, {{[node.typecast_value(“12”) #=> 12]}}

@param value The value that is being typecast.

@details [:type options]

  "integer"::
    converts +value+ to an integer with #to_i
  "boolean"::
    checks whether +value+, after removing spaces, is the literal
    "true"
  "datetime"::
    Parses +value+ using Time.parse, and returns a UTC Time
  "date"::
    Parses +value+ using Date.parse

@return [Integer, Boolean, Time, Date, Object]

  The result of typecasting +value+.

@note

  If +self+ does not have a "type" key, or if it's not one of the
  options specified above, the raw +value+ will be returned.
     # File lib/extlib/hash.rb, line 378
378:   def typecast_value(value)
379:     return value unless @type
380:     proc = self.class.typecasts[@type]
381:     proc.nil? ? value : proc.call(value)
382:   end
undasherize_keys(params) click to toggle source

Take keys of the form foo-bar and convert them to foo_bar

     # File lib/extlib/hash.rb, line 398
398:   def undasherize_keys(params)
399:     params.keys.each do |key, value|
400:       params[key.tr("-", "_")] = params.delete(key)
401:     end
402:     params
403:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.