Class: Rulix::Mutators::Truncate

Inherits:
Object
  • Object
show all
Defined in:
lib/rulix/mutators/truncate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length) ⇒ Truncate

Returns a new instance of Truncate.



6
7
8
# File 'lib/rulix/mutators/truncate.rb', line 6

def initialize length
  self.length = length
end

Instance Attribute Details

#lengthObject

Returns the value of attribute length.



4
5
6
# File 'lib/rulix/mutators/truncate.rb', line 4

def length
  @length
end

Instance Method Details

#call(string) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
# File 'lib/rulix/mutators/truncate.rb', line 14

def call string
  raise ArgumentError, "argument is not a string" unless string.is_a? String
  
  string.slice(0, length)
end

#to_procObject



10
11
12
# File 'lib/rulix/mutators/truncate.rb', line 10

def to_proc
  method(:call)
end