Class: RuboCop::Cop::HashTransformMethod::Captures

Inherits:
Struct
  • Object
show all
Defined in:
lib/rubocop/cop/mixin/hash_transform_method.rb

Overview

Internal helper class to hold match data

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#transformed_argnameObject

Returns the value of attribute transformed_argname

Returns:

  • (Object)

    the current value of transformed_argname


13
14
15
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 13

def transformed_argname
  @transformed_argname
end

#transforming_body_exprObject

Returns the value of attribute transforming_body_expr

Returns:

  • (Object)

    the current value of transforming_body_expr


13
14
15
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 13

def transforming_body_expr
  @transforming_body_expr
end

#unchanged_body_exprObject

Returns the value of attribute unchanged_body_expr

Returns:

  • (Object)

    the current value of unchanged_body_expr


13
14
15
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 13

def unchanged_body_expr
  @unchanged_body_expr
end

Instance Method Details

#noop_transformation?Boolean

Returns:

  • (Boolean)
[View source]

14
15
16
17
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 14

def noop_transformation?
  transforming_body_expr.lvar_type? &&
    transforming_body_expr.children == [transformed_argname]
end

#transformation_uses_both_args?Boolean

Returns:

  • (Boolean)
[View source]

19
20
21
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 19

def transformation_uses_both_args?
  transforming_body_expr.descendants.include?(unchanged_body_expr)
end

#use_transformed_argname?Boolean

Returns:

  • (Boolean)
[View source]

23
24
25
26
27
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 23

def use_transformed_argname?
  transforming_body_expr.each_descendant(:lvar).any? do |node|
    node.source == transformed_argname.to_s
  end
end