I am trying to work in IRB to get an understanding for some code that I found online.
我正在尝试在IRB工作,以了解我在网上找到的一些代码。
I am able to require a file which eventually imports this file:
我能够要求最终导入此文件的文件:
module LinkedIn
module Api
logger.debug "....7"
module QueryMethods
logger.debug "....6"
def profile(options={})
logger.debug "....1"
path = person_path(options)
simple_query(path, options)
end
def connections(options={})
path = "#{person_path(options)}/connections"
simple_query(path, options)
end
def network_updates(options={})
path = "#{person_path(options)}/network/updates"
simple_query(path, options)
end
def company(options = {})
path = company_path(options)
simple_query(path, options)
end
def test(options = {})
logger.debug "helllllooooo"
end
private
logger.debug "....2"
def simple_query(path, options={})
logger.debug "....3"
fields = options.delete(:fields) || LinkedIn.default_profile_fields
if options.delete(:public)
path +=":public"
elsif fields
path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
end
headers = options.delete(:headers) || {}
params = options.map { |k,v| "#{k}=#{v}" }.join("&")
path += "?#{params}" if not params.empty?
Mash.from_json(get(path, headers))
end
def person_path(options)
logger.debug "....4"
path = "/people/"
if id = options.delete(:id)
path += "id=#{id}"
elsif url = options.delete(:url)
path += "url=#{CGI.escape(url)}"
else
path += "~"
end
end
def company_path(options)
path = "/companies/"
if id = options.delete(:id)
path += "id=#{id}"
elsif url = options.delete(:url)
path += "url=#{CGI.escape(url)}"
elsif name = options.delete(:name)
path += "universal-name=#{CGI.escape(name)}"
elsif domain = options.delete(:domain)
path += "email-domain=#{CGI.escape(domain)}"
else
path += "~"
end
end
end
end
end
This code is a wrapper for LinkedIn and I found it here: https://github.com/pengwynn/linkedin/blob/master/lib/linked_in/api/query_methods.rb
这段代码是LinkedIn的包装,我在这里找到它:https://github.com/pengwynn/linkedin/blob/master/lib/linked_in/api/query_methods.rb
It is mostly off the shelf, but this test bit is mine:
它主要是现成的,但这个测试位是我的:
def test(options = {})
logger.debug "helllllooooo"
end
I copied these files locally, and in IRB I can perform some commands, but I can not for some reason do something like client.test
whereas I can do something like client.profile
.
我在本地复制这些文件,在IRB中我可以执行一些命令,但我不能出于某种原因做类似client.test的事情,而我可以做类似client.profile的事情。
Also none of the debug statements show up in IRB. Do I have to start IRB with some sort of a flag to see the debug?
此外,IRB中没有显示任何调试语句。我是否必须使用某种标志启动IRB以查看调试?
2 个解决方案
#1
3
logger is part of rails
记录器是rails的一部分
irb is just a ruby command line interpreter
irb只是一个ruby命令行解释器
use 'rails console' to get a command line interface with the rails infrastructure running.
使用'rails console'获取运行rails infrastructure的命令行界面。
use puts as a substitute for logger while using irb
使用irb时使用puts作为记录器的替代品
EDIT
You'll never get anywhere trying to run that code in irb, instead, copy your file to yourapp/lib, then do a
你永远不会尝试在irb中运行该代码,而是将文件复制到yourapp / lib,然后执行
rails console
Now RAILS is booted up, but with a command line interface, then try
现在启动RAILS,但是使用命令行界面,然后尝试
include LinkedIn::Api::QueryMethods
test
now you can also use logger.debug
现在你也可以使用logger.debug
#2
0
Looking an answer to the same question, I tried this which I found somewhere online and it worked:
寻找同一个问题的答案,我试过这个,我在网上找到了它并且它有效:
2.0.0-p353 :020 > ActiveRecord::Base.logger.debug "your whatever text"
#1
3
logger is part of rails
记录器是rails的一部分
irb is just a ruby command line interpreter
irb只是一个ruby命令行解释器
use 'rails console' to get a command line interface with the rails infrastructure running.
使用'rails console'获取运行rails infrastructure的命令行界面。
use puts as a substitute for logger while using irb
使用irb时使用puts作为记录器的替代品
EDIT
You'll never get anywhere trying to run that code in irb, instead, copy your file to yourapp/lib, then do a
你永远不会尝试在irb中运行该代码,而是将文件复制到yourapp / lib,然后执行
rails console
Now RAILS is booted up, but with a command line interface, then try
现在启动RAILS,但是使用命令行界面,然后尝试
include LinkedIn::Api::QueryMethods
test
now you can also use logger.debug
现在你也可以使用logger.debug
#2
0
Looking an answer to the same question, I tried this which I found somewhere online and it worked:
寻找同一个问题的答案,我试过这个,我在网上找到了它并且它有效:
2.0.0-p353 :020 > ActiveRecord::Base.logger.debug "your whatever text"