Class: Appendable

Inherits:
Array show all
Defined in:
lib/active_form/core_extensions.rb

Direct Known Subclasses

CssAttribute, JavascriptAttribute, StyleAttribute

Instance Method Summary collapse

Methods included from ActiveSupport::CoreExtensions::Array::Dropdown

#to_dropdown

Instance Method Details

#+(string_or_array) ⇒ Object

[View source]

134
135
136
# File 'lib/active_form/core_extensions.rb', line 134

def +(string_or_array)
  self << value_to_array(string_or_array)
end

#-(string_or_array) ⇒ Object

[View source]

138
139
140
141
# File 'lib/active_form/core_extensions.rb', line 138

def -(string_or_array)
  remove = value_to_array(string_or_array)
  self.reject! { |v| remove.include?(v) }
end

#<<(string_or_array) ⇒ Object

[View source]

125
126
127
128
129
130
131
132
# File 'lib/active_form/core_extensions.rb', line 125

def <<(string_or_array)
  replacement = Array.new(self)
  value_to_array(string_or_array).each do |value|   
    replacement << value unless replacement.include?(value)
  end
  self.replace(replacement)
  self
end

#join(delimiter = self.class.delimiter) ⇒ Object Also known as: to_s

[View source]

143
144
145
# File 'lib/active_form/core_extensions.rb', line 143

def join(delimiter = self.class.delimiter)
  super(delimiter)
end

#replace(*args) ⇒ Object

[View source]

121
122
123
# File 'lib/active_form/core_extensions.rb', line 121

def replace(*args)
  super(value_to_array(args))
end

#write {|_self| ... } ⇒ Object Also known as: define

Yields:

  • (_self)

Yield Parameters:

  • _self (Appendable)

    the object that the method was called on

[View source]

116
117
118
# File 'lib/active_form/core_extensions.rb', line 116

def write
  yield self if block_given?
end