Class: SimpleHelpers::Support

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

Class Method Summary collapse

Class Method Details

.certified_array!(splat_arg) ⇒ Object



3
4
5
6
# File 'lib/simple_helpers/support.rb', line 3

def self.certified_array!(splat_arg)
  array = splat_arg.first.is_a?(Array) ? splat_arg.first : Array(splat_arg)
  array.collect{|item| item.to_s}
end

.create_method(controller, name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/simple_helpers/support.rb', line 8

def self.create_method(controller, name)
  controller.class_eval do
    define_method(name) do |*args|
      if args.empty?
        send "#{name}_get"
      else
        send "#{name}_set", args.first
      end
    end

    define_method("#{name}_set") do |*args|
      instance_variable_set "@#{name}", args.first
    end

    define_method("#{name}_get") do |*args|
      "%{prefix}%{prefix_separator}%{content}%{suffix_separator}%{suffix}" %
        SimpleHelpers::Support.simple_helper_parts(controller, name)
    end
  end
end