Skip to content

Instantly share code, notes, and snippets.

@splattael
Last active March 22, 2016 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save splattael/e071f987c908584d2c62 to your computer and use it in GitHub Desktop.
Save splattael/e071f987c908584d2c62 to your computer and use it in GitHub Desktop.
Error in ./foo.cr:22: undefined method 'uid' for Nil (compile-time type is Rank?)
p list.by("foo").uid
^~~
================================================================================
Nil trace:
./foo.cr:13
def by(uid)
^~
./foo.cr:14
@entries.find { |rank| rank.uid == uid }
^~~~
/opt/crystal/src/enumerable.cr:218
def find(if_none = nil)
/opt/crystal/src/enumerable.cr:222
if_none
^~~~~~~
/opt/crystal/src/enumerable.cr:218
def find(if_none = nil)
^
class Rank
getter uid
def initialize(@uid)
end
end
class RankList
@entries = [] of Rank
def initialize(@entries)
@entries
end
def by(uid)
@entries.find { |rank| rank.uid == uid }
end
end
list = RankList.new(
[Rank.new("foo")]
)
p list.by("foo").uid
p list.by("bar").uid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment