Class: Symbol

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

Overview

Extensions for Symbol

Instance Method Summary collapse

Instance Method Details

#/(obj) ⇒ Object

A convenient way to do File.join Usage:

:dir/:file # => 'dir/file'


17
18
19
# File 'lib/ramaze/snippets/divide.rb', line 17

def / obj
  self.to_s / obj
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)

[1, 2, 3].map(&:to_s)    # => ['1', '2', '3']
%w[a b c].map(&:to_sym)  # => [:a, :b, :c]


20
21
22
# File 'lib/ramaze/snippets/symbol/to_proc.rb', line 20

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