Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

safe_nested_calls

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

safe_nested_calls

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

safe_nested_calls

This gem allows you to safely call nested methods on an object, and not worry about whether or not the methods are defined. It is very useful for managing dynamically created objects.

Installation

gem install 'safe_nested_calls'

If you are using Rails, then it will automatically load on server start, but if not, somewhere in your code, put:

require 'safe_nested_calls'

Usage

safe_nested_calls adds two extra methods to Object,

nested_respond_to? and safe_nested_method.

nested_respond_to?

if object.nested_respond_to?(:one, :two, :three)
  

which is equivalent to

if object.respond_to? :one
	if object.one.respond_to? :two
		object.one.two.respond_to? :three

safe_nested_method

This method can call the actual nested method desired, with optional parameters

object.safe_nested_method(:one, :two, :three) => returns object.one.two.three
  

To use parameters, use a hash of :method => args, where args are the method arguments

object.safe_nested_method(:one => 1, :two => [1, 2], :three => [1,2,3])
  

which is equivalent to

object.one(1).two(1,2).three(1,2,3)
  
Parameters

If you need to call of mix of methods with and without parameters, set the arguments for the methods without parameters to :none

object.safe_nested_method(:get => :none, :increment => 4, :save => :none)
  

which is equivalent to

object.get().increment(4).save()

FAQs

Package last updated on 24 Feb 2012

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