class Ameba::Rule::Performance::MapInsteadOfBlock
- Ameba::Rule::Performance::MapInsteadOfBlock
- Ameba::Rule::Performance::Base
- Ameba::Rule::Base
- Reference
- Object
Overview
This rule is used to identify usage of sum/product
calls
that follow map
.
For example, this is considered inefficient:
(1..3).map(&.*(2)).sum
And can be written as this:
(1..3).sum(&.*(2))
YAML configuration example:
Performance/MapInsteadOfBlock:
Enabled: true
Included Modules
- YAML::Serializable
- YAML::Serializable::Strict
Defined in:
ameba/rule/performance/map_instead_of_block.crConstant Summary
-
CALL_NAMES =
["sum", "product"] of ::String
-
MAP_NAME =
"map"
-
MSG =
"Use `%s {...}` instead of `map {...}.%s`"
Constructors
-
.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
This rule is used to identify usage of
sum/product
calls that followmap
. -
.new(config = nil)
This rule is used to identify usage of
sum/product
calls that followmap
.
Instance Method Summary
- #description : String
- #description=(description : String)
- #enabled : Bool
- #enabled=(enabled : Bool)
- #excluded : Array(String)?
- #excluded=(excluded : Array(String)?)
- #severity : Ameba::Severity
- #severity=(severity : Ameba::Severity)
- #test(source, node : Crystal::Call)
- #test(source)
Instance methods inherited from class Ameba::Rule::Performance::Base
catch(source : Source)
catch
Constructor methods inherited from class Ameba::Rule::Performance::Base
new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)new(config = nil) new
Instance methods inherited from class Ameba::Rule::Base
==(other)
==,
catch(source : Source)
catch,
excluded?(source)
excluded?,
group
group,
hash
hash,
name
name,
special?
special?,
test(source : Source, node : Crystal::ASTNode, *opts)test(source : Source) test
Class methods inherited from class Ameba::Rule::Base
parsed_doc
parsed_doc
Constructor Detail
def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
#
This rule is used to identify usage of sum/product
calls
that follow map
.
For example, this is considered inefficient:
(1..3).map(&.*(2)).sum
And can be written as this:
(1..3).sum(&.*(2))
YAML configuration example:
Performance/MapInsteadOfBlock:
Enabled: true
def self.new(config = nil)
#
This rule is used to identify usage of sum/product
calls
that follow map
.
For example, this is considered inefficient:
(1..3).map(&.*(2)).sum
And can be written as this:
(1..3).sum(&.*(2))
YAML configuration example:
Performance/MapInsteadOfBlock:
Enabled: true