Skip to content

Instantly share code, notes, and snippets.

@kaineer
Created September 17, 2010 05:56
Show Gist options
  • Save kaineer/583793 to your computer and use it in GitHub Desktop.
Save kaineer/583793 to your computer and use it in GitHub Desktop.
Плюрализатор на ruby
## Output
1 фонарь
21 фонарь
11 фонарей
2 фонаря
20 фонарей
100 фонарей
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