Last active
December 24, 2015 07:49
-
-
Save rrreeeyyy/6766821 to your computer and use it in GitHub Desktop.
配列が循環参照するか検出するメソッド Array#is_cycle?
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 Array | |
def is_cycle? | |
!!(self.inspect =~ /[^"]\[\.\.\.\][^"]/) | |
end | |
end |
↑ 直した
↑ "[...]" という文字列を含む循環参照配列に対して無力だったので更に直した
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AuToPP: れいくんのArray#is_cycle?、「a = [1, 2]; b = [4, a]; a << b」みたいなのは多分だめなんだよね。 [http://twitter.com/AuToPP/status/384923933876568064]