I'm trying to take a bunch of lambdas that do the same thing and DRY them up by breaking it out in to a method. The code in question is in a module / class and I've forgotten the correct way to do this :/
The docs show an example like this using a lambda -
module Mutations
class MyMutation < BaseMutation
argument :name, String, required: true, prepare: -> (value, ctx) { value.strip! }
end
end
I've tried -
module Mutations
class MyMutation < BaseMutation
argument :name, String, required: true, prepare: :no_whitespace
def no_whitespace(value)
value.strip!
end
end
end
But get a method not found on class error.
I also tried moving it to it's own module or class -
module Mutations
class MyMutation < BaseMutation
argument :name, String, required: true, prepare: Testing::no_whitespace
end
class Testing
def no_whitespace(value)
value.strip!
end
end
end
I know it's something silly but I can't find the right combinations to get this working and my brain has forgotten too much Ruby to remember what to google.