Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby lambda context

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.

like image 644
David K. Avatar asked Jun 28 '10 15:06

David K.


People also ask

What does Lambda do in Ruby?

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.

How do you call a Lambda function in Ruby?

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.

What is event and context in Lambda function?

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.


1 Answers

the code you are looking for is

temp.instance_eval(&callable)
like image 197
Glenjamin Avatar answered Oct 07 '22 01:10

Glenjamin