Sha256: 645e3ebd1e2340e1f3d277c1a7b6afb982421157740ba5b08b66cb7f7c79800c

Contents?: true

Size: 420 Bytes

Versions: 4

Compression:

Stored size: 420 Bytes

Contents

module Marty::Enum
  def method_missing(meth, *args, &block)
    if meth.to_s =~ /^[A-Z_]+$/ && args.empty?
      items = self.all
      items.each { |item|
        name = item.name.upcase.gsub(/[\/\s-]/, '_')
        self.define_singleton_method(name) do
          item
        end unless self.methods.member?(name.to_sym)
      }

      return self.send(meth) if self.methods.member?(meth)
    end
    super
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
marty-0.5.15 app/models/marty/enum.rb~
marty-0.5.14 app/models/marty/enum.rb~
marty-0.5.13 app/models/marty/enum.rb~
marty-0.5.12 app/models/marty/enum.rb~