Skip to content

Instantly share code, notes, and snippets.

@myun2
Created June 14, 2019 11:52
Show Gist options
  • Save myun2/64b29b59979d995a333c1b9cfbf858cb to your computer and use it in GitHub Desktop.
Save myun2/64b29b59979d995a333c1b9cfbf858cb to your computer and use it in GitHub Desktop.
def int(name)
eval <<-EOS
public
def #{name}=(value)
raise '#{name} is required' if value == nil
raise 'Type is mismatch' unless value.is_a? Integer
@#{name} = value
end
EOS
end
def string(name)
eval <<-EOS
public
def #{name}=(value)
raise '#{name} is required' if value == nil
raise 'Type is mismatch' unless value.is_a? String
@#{name} = value
end
EOS
end
def string?(name)
eval <<-EOS
public
def #{name}=(value)
raise 'Type is mismatch' unless value == nil || value.is_a?(String)
@#{name} = value
end
EOS
end
class Example
int :id
string :name
string? :description
end
Example.new.id = 3
Example.new.id = "3"
Example.new.id = nil
Example.new.description = 3
Example.new.description = "3"
Example.new.description = nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment