Class: HumanName::Methods

Inherits:
Module
  • Object
show all
Defined in:
lib/human_name/methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(first_name_method = :first_name, last_name_method = :last_name) ⇒ Methods

Returns a new instance of Methods.



3
4
5
6
# File 'lib/human_name/methods.rb', line 3

def initialize(first_name_method = :first_name, last_name_method = :last_name)
  @__first_name_method  = first_name_method
  @__last_name_method   = last_name_method
end

Instance Method Details

#included(base) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/human_name/methods.rb', line 8

def included(base)
  fname = @__first_name_method
  lname = @__last_name_method
  base.class_eval do
    define_method :human_name do
      first_name  = send fname
      last_name   = send lname
      HumanName.new(first_name, last_name)
    end

    extend Forwardable
    def_delegators :human_name, :full_name, :name_initials
  end
end