Skip to content

Instantly share code, notes, and snippets.

@KrauseFx
Created August 5, 2017 03:29
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 KrauseFx/e2cac9c00d03423838b064049e737d95 to your computer and use it in GitHub Desktop.
Save KrauseFx/e2cac9c00d03423838b064049e737d95 to your computer and use it in GitHub Desktop.
# as this is used in the fastlane code base a lot, and lots of people ask about it
# .length method
"my string".length # => 9
"".length # => 0
nil.length # NoMethodError: undefined method `length' for nil:NilClass
# .to_s method
"my string".to_s # => "my string"
"".to_s # => ""
nil.to_s # => ""
nil.to_s == "".to_s# => true
# combine the 2
nil.to_s.length == 0 # => true
"".to_s.length == 0 # => true
"a".to_s.length == 0 # false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment