Created
September 29, 2010 13:26
-
-
Save vovka/602743 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Есть такая функция: | |
def code_unique? klass, msg_assignment_proc=Proc.new | |
if @@error_classes.empty? | |
true | |
else | |
if @@error_classes.map(&:new).map(&:code).include?(klass.new.code) | |
msg_assignment_proc.call "Error code value repeating: #{klass.new.code}" | |
false | |
else | |
true | |
end | |
end | |
end | |
# В общем виде можно представить так: | |
def function? a, proc=Proc.new | |
if @@some_array.empty? | |
true | |
else | |
if @@some_array.include?(a) | |
proc.call "some message" | |
false | |
else | |
true | |
end | |
end | |
end | |
# Как переписать тело функции так, чтобы оно представляло из себя одну строку и при этом не использовались бы условные операторы и точки-с-запятой? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Решение конечно не очень читабельное, точнее совсем нечитабельное и практический смысл от него мал. Зато так просто для разминки можно подумать.
Есть подсказка http://gist.github.com/602755