0

I have the following class:

class Message
  extend ActiveModel::Naming
  include ActiveModel::Conversion

  attr_accessor :name, :emails, :custom_content

  def initialize(attrs = {})
    attrs.each do |k, v|
      self.send "#{k}=", v
    end
  end

  def persisted?
    false
  end

  def email_list
    self.emails.split(",").collect { |email| {:email => email.delete(" ")} }
  end 
end

I always want to capitalize the name attribute instead of having to always do it when I call the attribute in code.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189

1 Answers1

0

Figured it out:

class Message
  extend ActiveModel::Naming
  include ActiveModel::Conversion

  attr_accessor :name, :emails, :custom_content

  def initialize(attrs = {})
    attrs.each do |k, v|
      self.send "#{k}=", v
    end
  end

  def persisted?
    false
  end

  #Fix is here
  def name=(s)
    @name = s.titleize
  end

  def email_list
    self.emails.split(",").collect { |email| {:email => email.delete(" ")} }
  end 
end
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189