Guest User

Untitled

a guest
Jan 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. class String
  2. def sex_code
  3. if ["male", "男"].include? self
  4. 0
  5. elsif self == "女"
  6. 1
  7. else
  8. self
  9. end
  10. end
  11. end
  12.  
  13. p String.instance_methods.grep(/^sex/) # => [:sex_code]
  14.  
  15. p "male".sex_code # => 0
  16. p "女".sex_code # => 1
  17. p "other".sex_code # => "other"
Add Comment
Please, Sign In to add comment