Search code examples
crystal-lang

crystal Error: undefined method 'length' for Array(String)


converting something from ruby to crystal

$ cat test.cr
puts ARGV.length

works in ruby, but crystal

$ crystal test.cr

Showing last frame. Use --error-trace for full trace.

error in line 1
Error: undefined method 'length' for Array(String)

Solution

  • appears the correct method is "size". crystal doesn't have as many aliases, to standardize.

    $ cat test.cr
    puts ARGV.size
    
    $ crystal test.cr 1 2 3
    3