Lets say I have the following ruby definition at the topmost level
callable = lambda {"#{hi}"}
and suppose that later on I create an object called temp
that has a method called hi
. Now what I would like to do is call callable
within the context of temp
. I have tried doing
temp.instance_eval do callable.call end
but this gives me the error "NameError: undefined local variable or method 'hi' for main:Object
". I would like to know if there is any way to rebind the context of callable
to temp
so that I don't get an error message? I know that I could define method_missing
on main:Object and reroute all method calls to temp
but this seems like way too big of a hack to accomplish what I want.
You can run Ruby code in AWS Lambda. Lambda provides runtimes for Ruby that run your code to process events. Your code runs in an environment that includes the AWS SDK for Ruby, with credentials from an AWS Identity and Access Management (IAM) role that you manage.
The first step is to load the modules we use: aws-sdk loads the AWS SDK for Ruby module we use to invoke the Lambda function. json loads the JSON module we use to marshall and unmarshall the request and response payloads. os loads the OS module we use to ensure we can run our Ruby application on Microsoft Windows.
Event and contextEvent object is the first argument of the handler function and contains information about the event, for example an API request event holds the HTTP request object. Context object contains information about the invocation, function configuration and execution environment.
the code you are looking for is
temp.instance_eval(&callable)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With