Skip to content

Instantly share code, notes, and snippets.

@rrreeeyyy
Last active December 24, 2015 07:49
Show Gist options
  • Save rrreeeyyy/6766821 to your computer and use it in GitHub Desktop.
Save rrreeeyyy/6766821 to your computer and use it in GitHub Desktop.
配列が循環参照するか検出するメソッド Array#is_cycle?
class Array
def is_cycle?
!!(self.inspect =~ /[^"]\[\.\.\.\][^"]/)
end
end
@rrreeeyyy
Copy link
Author

AuToPP: れいくんのArray#is_cycle?、「a = [1, 2]; b = [4, a]; a << b」みたいなのは多分だめなんだよね。 [http://twitter.com/AuToPP/status/384923933876568064]

@rrreeeyyy
Copy link
Author

↑ 直した

@rrreeeyyy
Copy link
Author

↑ "[...]" という文字列を含む循環参照配列に対して無力だったので更に直した

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment