Block interpolation submission method for blocks

I'm a newbie working on some Ruby tutorials and don't understand how to use the method sendbelow. I can see that the send method reads the value of the attribute iterator, but the Ruby documentation states that the send method accepts the method preceding the colon. So my confusion is how the submit method below interpolates the attribute variable renamed.

module FormatAttributes
  def formats(*attributes)
    @format_attribute = attributes
  end

  def format_attributes
    @format_attributes
  end
end

module Formatter
  def display
    self.class.format_attributes.each do |attribute|
      puts "[#{attribute.to_s.upcase}] #{send(attribute)}"
    end
  end
end

class Resume
  extend FormatAttributes
  include Formatter
  attr_accessor :name, :phone_number, :email, :experience
  formats :name, :phone_number, :email, :experience
end
+5
source share
2 answers

It does not "call the iterator value", but instead calls a method with this name. In this case, due to the declaration, attr_accessorthese methods are mapped to properties.

object.send('method_name') object.send(:method_name) object.method_name . , send(:foo) foo foo .

module , include, send Resume.

+2

send Documentation

, , :

def show
 p "hi"
end

x = "show"
y = :show

"#{send(y)}"   #=> "hi"
"#{send(x)}"   #=> "hi"
0

All Articles