home.social

#rubystrings — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #rubystrings, aggregated by home.social.

  1. We are kind of used to this, but still it is somhow illogical: A Range object, which represents *empty*, can still have an effect when used as a string index:

    range = 0..-3
    range.to_a.empty? #=> true
    "Ruby"[range] #=> "Ru"

    It feels less "wrong" when using Ruby's more recent beginless ranges:

    "Ruby"[..-3] #=> "Ru"

    #idiosyncratic #ruby #rubystrings

  2. We are kind of used to this, but still it is somhow illogical: A Range object, which represents *empty*, can still have an effect when used as a string index:

    range = 0..-3
    range.to_a.empty? #=> true
    "Ruby"[range] #=> "Ru"

    It feels less "wrong" when using Ruby's more recent beginless ranges:

    "Ruby"[..-3] #=> "Ru"

    #idiosyncratic #ruby #rubystrings

  3. We are kind of used to this, but still it is somhow illogical: A Range object, which represents *empty*, can still have an effect when used as a string index:

    range = 0..-3
    range.to_a.empty? #=> true
    "Ruby"[range] #=> "Ru"

    It feels less "wrong" when using Ruby's more recent beginless ranges:

    "Ruby"[..-3] #=> "Ru"

    #idiosyncratic #ruby #rubystrings

  4. We are kind of used to this, but still it is somhow illogical: A Range object, which represents *empty*, can still have an effect when used as a string index:

    range = 0..-3
    range.to_a.empty? #=> true
    "Ruby"[range] #=> "Ru"

    It feels less "wrong" when using Ruby's more recent beginless ranges:

    "Ruby"[..-3] #=> "Ru"

    #idiosyncratic #ruby #rubystrings

  5. We are kind of used to this, but still it is somhow illogical: A Range object, which represents *empty*, can still have an effect when used as a string index:

    range = 0..-3
    range.to_a.empty? #=> true
    "Ruby"[range] #=> "Ru"

    It feels less "wrong" when using Ruby's more recent beginless ranges:

    "Ruby"[..-3] #=> "Ru"

    #idiosyncratic #ruby #rubystrings