Skip to main content

.any

@-Doing travel kata
- any? vs empty?
https://stackoverflow.com/questions/6245929/check-for-array-not-empty-any

> [nil, 1].any?
=> true
>> [nil, nil].any?
=> false

- Using not in block
def dont_give_me_five(start,end_)
    (start..end_).count { | i | not i.to_s.include? '5' }
end

- Global $, Class @@ and Instance @ Variables.
Never use global because it makes isolating bugs hard.
http://www.rubyist.net/~slagell/ruby/globalvars.html

https://stackoverflow.com/questions/12358084/whats-difference-between-and-in-a-module

module A
  @@a = 5
end

class B
  include A
  puts @@a # => 5
end

module A
  @a = 5
end

class B
  include A
  puts @a # => nil
end

-Regex cheatsheet
http://www.rexegg.com/regex-quickstart.html

-Array lessons
c = [1,2,3,4]
 => [1, 2, 3, 4]
2.4.1 :038 > c[0..3]
 => [1, 2, 3, 4]
2.4.1 :039 > c[0...3]
=> [1, 2, 3]
2.4.1 :051 > c[0..-2]
 => [1, 2, 3] #from index 0 to index 2
2.4.1 :054 > c[1+1..-1]
 => [3, 4] #from index 2 to index 3


Comments