Class: Ruber::World::MutableProjectList
- Inherits:
-
ProjectList
- Object
- ProjectList
- Ruber::World::MutableProjectList
- Defined in:
- lib/ruber/world/project_list.rb
Overview
A ProjectList which allows to change the contents of the list.
Instance Method Summary (collapse)
-
- (MutableProjectList) add(*projects)
Adds projects to the list.
-
- (MutableProjectList) clear
Removes all the elements from the list.
-
- (MutableProjectList) clone
Override of
Object#clone
. -
- (MutableProjectList) delete_if {|prj| ... }
Removes from the list all the projects for which the block returns true.
-
- (MutableProjectList) dup
Override of
Object#dup
. -
- (MutableProjectList) initialize(prjs = [])
constructor
A new instance of MutableProjectList.
-
- (MutableProjectList) merge!(prjs)
Adds the projects contained in another list to this list.
-
- (Project?) remove(prj)
Removes a project from the list.
Methods inherited from ProjectList
#==, #[], #each, #empty?, #eql?, #hash, #project_hash, #size
Methods included from Enumerable
Constructor Details
- (MutableProjectList) initialize(prjs = [])
A new instance of MutableProjectList
171 172 173 |
# File 'lib/ruber/world/project_list.rb', line 171 def initialize prjs = [] @projects = Hash[prjs.map{|prj| [prj.project_name, prj]}] end |
Instance Method Details
- (MutableProjectList) add(*projects)
Adds projects to the list
205 206 207 208 209 |
# File 'lib/ruber/world/project_list.rb', line 205 def add *projects projects.flatten.each do |prj| @projects[prj.project_file] = prj end end |
- (MutableProjectList) clear
Removes all the elements from the list
243 244 245 246 |
# File 'lib/ruber/world/project_list.rb', line 243 def clear @projects.clear self end |
- (MutableProjectList) clone
Override of Object#clone
187 188 189 190 191 192 193 194 |
# File 'lib/ruber/world/project_list.rb', line 187 def clone res = self.class.new self if frozen? res.freeze res.project_hash.freeze end res end |
- (MutableProjectList) delete_if {|prj| ... }
Removes from the list all the projects for which the block returns true
256 257 258 259 |
# File 'lib/ruber/world/project_list.rb', line 256 def delete_if &blk @projects.delete_if{|_, prj| blk.call prj} self end |
- (MutableProjectList) dup
Override of Object#dup
179 180 181 |
# File 'lib/ruber/world/project_list.rb', line 179 def dup self.class.new self end |
- (MutableProjectList) merge!(prjs)
Adds the projects contained in another list to this list
218 219 220 221 222 223 224 |
# File 'lib/ruber/world/project_list.rb', line 218 def merge! prjs if prjs.is_a? ProjectList then @projects.merge! prjs.project_hash else @projects.merge! Hash[prjs.map{|prj| [prj.project_file, prj]}] end self end |
- (Project?) remove(prj)
Removes a project from the list
If the given project isn’t in the list, nothing is done
234 235 236 |
# File 'lib/ruber/world/project_list.rb', line 234 def remove prj @projects.delete prj.project_file end |