Class: Symbol

Inherits:
Object show all
Defined in:
lib/snippets/symbol/slash.rb,
lib/snippets/symbol/to_proc.rb

Instance Method Summary collapse

Instance Method Details

#/(*args) ⇒ Object

Helper method for File.join



3
4
5
# File 'lib/snippets/symbol/slash.rb', line 3

def /(*args)
  File.join(self.to_s, *args.map {|e| e.to_s})
end

#to_procObject

Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:

# The same as people.collect { |p| p.name }
people.collect(&:name)

# The same as people.select { |p| p.manager? }.collect { |p| p.salary }
people.select(&:manager?).collect(&:salary)


11
12
13
# File 'lib/snippets/symbol/to_proc.rb', line 11

def to_proc
  Proc.new { |*args| args.shift.__send__(self, *args) }
end