惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
C
Check Point Blog
Vercel News
Vercel News
Y
Y Combinator Blog
G
Google Developers Blog
P
Proofpoint News Feed
WordPress大学
WordPress大学
MongoDB | Blog
MongoDB | Blog
博客园 - 司徒正美
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
L
LangChain Blog
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
博客园_首页
B
Blog RSS Feed
The Cloudflare Blog
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog

博客园 - YD

Ruby 线程--生产者、消费者 Ruby的函数指针 Rails2.0学习--真困难 加班赶工,得不偿失——历史给你上六课 7. 创建Subversion服务之补充 Task Manager 1.1 开源软件:(Task Manager)任务管理-找出自己最需要完成的任务 小说阅读器 2.0 6. 创建 Subversion 服务 小说阅读器,有兴趣的同志可以试一下 不规则窗体的制作 播放 wave 文件 简单 Socket 通信 CRC 校验 C# 实现法 5. 多人协作 C# 中信号量的使用 4. 不要把不必要的文件版本化 3. 从 Repository 中恢复 2. 创建你的 Repository
如何查找某一函数的定义
YD · 2008-06-11 · via 博客园 - YD

今天在学《Agile Web Development with Rails, 2nd ed》的functional testing of controllers一节的时候。遇到了模拟浏览器get方法的一个函数,get。它的第三个参数可以往session里面放东西。我看的书是beta版,没有对get的参数列表的解释。开始我以为在rails文档库中可以找到定义。谁知道竟然没有。所以只能自已定位了。

原书上的函数调用代码为:
get :index, {}, { :user_id => users(:dave).id }

为了查找调用的这个get到底是哪个类的。我使用了set_trace_func这个函数。这个函数在ruby one-click installer安装后附带的《Programming Ruby》里详细介绍。它是Kernel模块的一个方法。在ruby的core文档库里可以找到说明。使用它,源码为:
    set_trace_func proc { |event, file, line, id, binding, classname|
      if (id.to_s == "get")
        printf "%8s %s:%-2d %10s %8s"n", event, file, line, id, classname
      end
    }
    get :index, {}, { :user_id => users(:dave).id }
    set_trace_func nil

这样,我就可以在控制台运行测试程序的时候查看输出了。输出为:
Loaded suite test/functional/login_controller_test
Started
    call c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/test_process.rb:354        get Test::Unit::TestCase
    line c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/test_process.rb:355        get Test::Unit::TestCase
    line c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/test_process.rb:355        get Test::Unit::TestCase
    line c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/test_process.rb:356        get Test::Unit::TestCase
  return c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.6/lib/action_controller/test_process.rb:355        get Test::Unit::TestCase
..
Finished in 6.499 seconds.

2 tests, 6 assertions, 0 failures, 0 errors

这样,我就可以在test_process.rb里找到get的源代码和注释了。