length of an array (also hashes) in ruby can written in (at least i know) two ways. calling length
or count
methods for an object. for string onjects you can use length
method
irb(main):001:0> x = "some string"
=> "some string"
irb(main):002:0> x.class
=> String
irb(main):003:0> x.length
=> 11
irb(main):005:0> y = (1..9).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
irb(main):006:0> y.length
=> 9
irb(main):007:0> y.count
=> 9
irb(main):008:0>
__contains__
equivalent in ruby may be include?
method. actually it's more likely to in
keyword.
irb(main):008:0> x.include?('s')
=> true
irb(main):009:0> y.include?('2')
=> false
irb(main):010:0> y.include?(2)
=> true
find_index
for arrays and index
for string may be helpful.
irb(main):013:0> y.find_index(3)
=> 2
irb(main):016:0> x.index('s')
=> 0
irb(main):017:0> x.index('s', 4) #the second argument is offset value.
=> 5
I am not an experienced rubyist but hope these would be helpful for first steps. Also hope, not to mislead you on your ruby path :)