Sha256: 7c2f82ddc40e42026079a14d62f33de0f0cbd013db937a3eb5bd4548ada81121
Contents?: true
Size: 1.77 KB
Versions: 2
Compression:
Stored size: 1.77 KB
Contents
class String # Changes an underscored string into a class reference. def _as_class # classify expects self to be plural self.classify.constantize end # For compatibility with the Symbol extensions. alias :_singularize :singularize alias :_pluralize :pluralize alias :_classify :classify end class Symbol # Changes an underscored symbol into a class reference. def _as_class; self.to_s._as_class; end # Changes a plural symbol into a singular symbol. def _singularize; self.to_s.singularize.to_sym; end # Changes a singular symbol into a plural symbol. def _pluralize; self.to_s.pluralize.to_sym; end # Changes a symbol into a class name string. def _classify; self.to_s.classify; end end class Array # Flattens the first level of self. def _flatten_once self.inject([]){|r, el| r + Array(el)} end # Rails 1.2.3 compatibility method. Copied from http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/core_ext/array/extract_options.rb?rev=7217 def _extract_options! last.is_a?(::Hash) ? pop : {} end end class Hash # An implementation of select that returns a Hash. def _select Hash[*self.select do |key, value| yield key, value end._flatten_once] end end class Object # Returns the metaclass of self. def _metaclass; (class << self; self; end); end # Logger shortcut. def _logger_debug s RAILS_DEFAULT_LOGGER.debug(s) if RAILS_DEFAULT_LOGGER end # Logger shortcut. def _logger_warn s if RAILS_DEFAULT_LOGGER RAILS_DEFAULT_LOGGER.warn(s) else $stderr.puts("has_many_polymorphs: #{s}") end end end class ActiveRecord::Base # Return the base class name as a string. def _base_class_name self.class.base_class.name.to_s end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
has_many_polymorphs-2.10 | lib/has_many_polymorphs/support_methods.rb |
has_many_polymorphs-2.9 | lib/has_many_polymorphs/support_methods.rb |