Amal
Amal

Reputation: 545

What does this statement in ruby mean?

I am new to ruby and didn't understand what this statement does.

dependency 'multi_json'

More info: https://github.com/vongrippen/bitbucket/blob/master/lib/bitbucket_rest_api/request/jsonize.rb#L11

Any ruby experts, help please.

Upvotes: 1

Views: 55

Answers (2)

Nimir
Nimir

Reputation: 5839

That's not a core ruby method. It comes from the parent class Faraday::Middleware

https://github.com/lostisland/faraday/blob/master/lib/faraday/middleware.rb#L12

Here is the implementation:

# Executes a block which should try to require and reference dependent libraries
def self.dependency(lib = nil)
  lib ? require(lib) : yield
rescue LoadError, NameError => error
  self.load_error = error
end

So what it basically do is trying to require the argument lib, in your case the 'multi-json' library.

Upvotes: 2

Jörg W Mittag
Jörg W Mittag

Reputation: 369428

It sends the message dependency to the implicit receiver self passing the String 'multi_json' as the only argument.

By the way: it's not a statement, it's an expression. Everything in Ruby is an expression, there are no statements.

Upvotes: 1

Related Questions