Skip to content
  • Sean Doyle's avatar
    73133fa3
    Delegate `ActiveStorage::Filename#to_str` to `#to_s` · 73133fa3
    Sean Doyle authored
    Supports checking String equality:
    
    ```ruby
    filename = ActiveStorage::Filename.new("file.txt")
    filename == "file.txt" # => true
    filename in "file.txt" # => true
    "file.txt" == filename # => true
    ```
    
    Prior to this change, tests asserting equality would need to coerce the
    `ActiveStorage::Filename` instance to a string:
    
    ```ruby
    blob = # create ActiveStorage::Blob
    
    assert_equal "file.txt", blob.filename.to_s
    ```
    
    After this change, the equality check will automatically coerce:
    
    ```ruby
    blob = # create ActiveStorage::Blob
    
    assert_equal "file.txt", blob.filename
    ```
    
    As an added benefit, the filename will match in `case` and `if ... in`
    statements:
    
    ```ruby
    blob = # create ActiveStorage::Blob
    filename = blob.filename
    
    case filename
    when "file.txt" then ...
    end
    
    if filename in "file.txt"
      # ...
    end
    ```
    73133fa3
    Delegate `ActiveStorage::Filename#to_str` to `#to_s`
    Sean Doyle authored
    Supports checking String equality:
    
    ```ruby
    filename = ActiveStorage::Filename.new("file.txt")
    filename == "file.txt" # => true
    filename in "file.txt" # => true
    "file.txt" == filename # => true
    ```
    
    Prior to this change, tests asserting equality would need to coerce the
    `ActiveStorage::Filename` instance to a string:
    
    ```ruby
    blob = # create ActiveStorage::Blob
    
    assert_equal "file.txt", blob.filename.to_s
    ```
    
    After this change, the equality check will automatically coerce:
    
    ```ruby
    blob = # create ActiveStorage::Blob
    
    assert_equal "file.txt", blob.filename
    ```
    
    As an added benefit, the filename will match in `case` and `if ... in`
    statements:
    
    ```ruby
    blob = # create ActiveStorage::Blob
    filename = blob.filename
    
    case filename
    when "file.txt" then ...
    end
    
    if filename in "file.txt"
      # ...
    end
    ```
To find the state of this project's repository at the time of any of these versions, check out the tags.
Loading