Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string_proc.rb

Overview

Adds ‘String#to_proc` to allow multiple method chain calls on each element of an enumerable using the `&` shorthand The default separator is . but can be changed with the String.proc_separator= setter

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.proc_separatorObject

Returns the value of attribute proc_separator.



9
10
11
# File 'lib/string_proc.rb', line 9

def proc_separator
  @proc_separator
end

Instance Method Details

#to_procObject



12
13
14
15
16
# File 'lib/string_proc.rb', line 12

def to_proc
  proc do |object|
    split(self.class.proc_separator).reduce(object) { |obj, method| obj.send(method) }
  end
end