Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
(C) John Mair (banisterfiend) 2010
instance_eval without changing self
Using local_eval
you get most of the benefits of instance_eval
with very few of the drawbacks: local instance variables are
accessible within the block and method lookups are directed to the
correct receiver. Unlike instance_eval
the self
of the
block is not changed.
LocalEval provides the local_eval
and local_eval_with
methods.
gem install local_eval
Using local_eval
we can add the functionality of the receiver to the
block:
class C
def hello(name)
"hello #{name}!"
end
end
o = C.new
@name = "John"
o.local_eval { hello(@name) } #=> "hello John!"
Since local_eval
does not alter the self
inside a block,
all methods with an implied receiver will be invoked with respect to
this local self. This means that all mutator methods defined on the receiver
will modify state on the block's self rather than on the receiver's
self. This is unlikely to be the desired behaviour; and so
we can use the capture
method to redirect method lookup to
the actual receiver. All code captured by the capture
block
will be instance_eval
'd against the actual receiver of the method.
class C
class << self
attr_reader :hello
def self.capture_test
# this code will be run against C
capture { @hello = :captured }
# this code will be run against the block context
@goodbye = :goobye
end
end
end
C.local_eval { capture_test }
C.hello #=> :captured
@goodbye #=> :goodbye
Makes use of companion libraries: Remix and Object2module
local_eval
is not threadsafe.
LocalEval is one of a series of experimental libraries that mess with the internals of Ruby to bring new and interesting functionality to the language, see also:
Problems or questions contact me at github
FAQs
Unknown package
We found that local_eval demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.