class Mutils::Lib::Helper
Helper: caching expensive repetitive operations
Attributes
constantize_cache[RW]
inflector_object[RW]
pluralize_cache[RW]
underscore_cache[RW]
Public Class Methods
new()
click to toggle source
# File lib/mutils/lib/helper.rb, line 11 def initialize self.inflector_object = Dry::Inflector.new self.pluralize_cache = {} self.underscore_cache = {} self.constantize_cache = {} end
Public Instance Methods
collection?(object)
click to toggle source
# File lib/mutils/lib/helper.rb, line 33 def collection?(object) object.respond_to?(:size) && !object.respond_to?(:each_pair) end
constantize(string)
click to toggle source
# File lib/mutils/lib/helper.rb, line 28 def constantize(string) constantize_cache[string] = Object.const_get string unless constantize_cache[string] constantize_cache[string] end
pluralize(string)
click to toggle source
# File lib/mutils/lib/helper.rb, line 23 def pluralize(string) pluralize_cache[string] = inflector_object.pluralize string unless pluralize_cache[string] pluralize_cache[string] end
underscore(string)
click to toggle source
# File lib/mutils/lib/helper.rb, line 18 def underscore(string) underscore_cache[string] = inflector_object.underscore string unless underscore_cache[string] underscore_cache[string] end