summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:06:48 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:06:48 -0700
commit42a539061293f8e745a9dc5b97b4415b6a275e04 (patch)
treefb268244b7ca95dd36e8136bcd3c02fd2a05632f /lib/puppet/parser
parenta07bbe2e711ee22a40e147c046997c8813ae3cc8 (diff)
Code smell: Use ||= for conditional initialization
Replaced 55 occurances of ([$@]?\w+) += +(.*) +(if +\1.nil\?|if +! *\1|unless +\1|unless +defined\?\(\1\))$ with \1 ||= \2 3 Examples: The code: @sync becomes: @sync The code: becomes: The code: if @yydebug becomes: if @yydebug
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/ast/branch.rb2
-rw-r--r--lib/puppet/parser/ast/caseopt.rb2
-rw-r--r--lib/puppet/parser/resource.rb2
3 files changed, 3 insertions, 3 deletions
diff --git a/lib/puppet/parser/ast/branch.rb b/lib/puppet/parser/ast/branch.rb
index 0be6ca018..96d065e4c 100644
--- a/lib/puppet/parser/ast/branch.rb
+++ b/lib/puppet/parser/ast/branch.rb
@@ -23,7 +23,7 @@ class Puppet::Parser::AST
super(arghash)
# Create the hash, if it was not set at initialization time.
- @children = [] unless defined?(@children)
+ @children ||= []
# Verify that we only got valid AST nodes.
@children.each { |child|
diff --git a/lib/puppet/parser/ast/caseopt.rb b/lib/puppet/parser/ast/caseopt.rb
index b18a40320..6cf36f94c 100644
--- a/lib/puppet/parser/ast/caseopt.rb
+++ b/lib/puppet/parser/ast/caseopt.rb
@@ -29,7 +29,7 @@ class Puppet::Parser::AST
@default = true if @value.is_a?(AST::Default)
end
- @default = false unless defined?(@default)
+ @default ||= false
@default
end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 65d657b63..ba2a5f3b0 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -27,7 +27,7 @@ class Puppet::Parser::Resource < Puppet::Resource
# Determine whether the provided parameter name is a relationship parameter.
def self.relationship_parameter?(name)
- @relationship_names = Puppet::Type.relationship_params.collect { |p| p.name } unless defined?(@relationship_names)
+ @relationship_names ||= Puppet::Type.relationship_params.collect { |p| p.name }
@relationship_names.include?(name)
end