Created
September 17, 2010 05:56
-
-
Save kaineer/583793 to your computer and use it in GitHub Desktop.
Плюрализатор на ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Output | |
1 фонарь | |
21 фонарь | |
11 фонарей | |
2 фонаря | |
20 фонарей | |
100 фонарей |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Integer | |
def pluralize( form_1, form_2, form_5 ) | |
u = self % 10 | |
d = ( self / 10 ) % 10 | |
if u == 1 && d != 1 | |
return "%d %s" % [ self, form_1 ] | |
elsif (2..4).include?( u ) && d != 1 | |
return "%d %s" % [ self, form_2 ] | |
else | |
return "%d %s" % [ self, form_5 ] | |
end | |
end | |
end | |
if $0 == __FILE__ | |
[ 1, 21, 11, 2, 20, 100 ].each {|i| | |
puts i.pluralize( *%w( фонарь фонаря фонарей ) ) | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment