New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

yield_from

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yield_from

  • 0.0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

yield_from: implementing yield from func() functionality by modifying yield *func() behavior

Usage

require 'yield_from'
class A
	extend YieldFrom
	def rec(n)
		return to_enum(:rec,n) if !block_given?
		return if n<0
		yield n
		yield *rec(n-1)
	end
	yield_from :rec
end
p A.new.rec(5).to_a # => [5, 4, 3, 2, 1, 0]

There are instance method version and local function version.

Motivation

In the above example, similar code was running until Ruby 2.7 .

class A
	def rec(n)
		return to_enum(:rec,n) if !block_given?
		return if n<0
		yield n
		rec(n-1, &proc)
	end
end
p A.new.rec(5).to_a # => [5, 4, 3, 2, 1, 0]

The bare proc got forbidden in Ruby 3.0.

You can see the discussion at https://qiita.com/cielavenir/items/0cc9189f2c40d6047d8b .

Acknowledgement

Learned Ruby decorator from Nakayama R et al. Automatic Translation of Decorators from Python to Ruby, The 77th National Convention of IPSJ, 2015

FAQs

Package last updated on 15 Jun 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc