Sha256: d31d3890682c3c999be200e6c7a2b3f5512a62558457a3c763629709f0304792

Contents?: true

Size: 292 Bytes

Versions: 2

Compression:

Stored size: 292 Bytes

Contents

# frozen_string_literal: true

class String
  def clamped(whitelist, strict: true, default: nil)
    is_included = proc do |item|
      if strict
        item == self
      else
        item.to_s == self
      end
    end

    return self if whitelist.any?(is_included)
    default
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clamped-1.0.1 lib/clamped/string.rb
clamped-1.0.0 lib/clamped/string.rb