Sha256: 57c1a019064f9dbcb57d42dd13bb2e9d5573a4d68a389e17456e87c65aec29c3
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
=begin rdoc ==violet/helpers.rb some handy class/methods and modifications. =end module Helpers require 'rexml/document' # REXML::Attributes#to_hash seems to be broken. class REXML::Attributes if defined? to_hash alias :to_hash_old :to_hash end # convert attributes to an instance of Hash. def to_hash h = Hash.new self.each { |key,value| h[key.to_sym] = value } h end end # ==Credits # taken from active_support/inflector.rb, # see http://rubyforge.org/projects/activesupport # # # ==Summary # Constantize tries to find a declared constant with the name specified # in the string. It raises a NameError when the name is not in CamelCase # or is not initialized. # # # ==Examples # Helpers.constantize("Module") #=> Module # Helpers.constantize("Class") #=> Class def Helpers.constantize(camel_cased_word) unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word raise NameError.new("#{camel_cased_word.inspect} is not a valid constant name!") end Object.module_eval("::#{$1}", __FILE__, __LINE__) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
libastag-0.0.1 | lib/violet/helpers.rb |