Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class String
- def sex_code
- if ["male", "男"].include? self
- 0
- elsif self == "女"
- 1
- else
- self
- end
- end
- end
- p String.instance_methods.grep(/^sex/) # => [:sex_code]
- p "male".sex_code # => 0
- p "女".sex_code # => 1
- p "other".sex_code # => "other"
Add Comment
Please, Sign In to add comment