lib/typical/dsl.rb in typical-0.1.0 vs lib/typical/dsl.rb in typical-0.1.1
- old
+ new
@@ -1,13 +1,15 @@
require "typical/type"
module Typical
module DSL
- def self.define_scalar_type(mod, name = nil)
- name ||= mod.name
- define_method("#{name}!") { Type.new(mod) }
- define_method("#{name}?") { Type.new(mod) | null }
+ module Define
+ private def define_scalar_type(mod, name = nil)
+ name ||= mod.name.split("::").last
+ define_method("#{name}!") { Type.new(mod) }
+ define_method("#{name}?") { Type.new(mod) | null }
+ end
end
BUILTIN_SCALAR_TYPES = [
Integer,
Float,
@@ -17,9 +19,10 @@
String,
Symbol,
Time,
].freeze
+ extend Define
BUILTIN_SCALAR_TYPES.each do |klass|
define_scalar_type(klass)
end
def null