Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ruby新手读源码.pdf
Search
覃明圆
January 20, 2015
350
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ruby新手读源码.pdf
覃明圆
January 20, 2015
More Decks by 覃明圆
See All by 覃明圆
思考middleware
qinmingyuan
0
220
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
420
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
540
YesSQL, Process and Tooling at Scale
rocio
174
15k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.2k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
380
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
580
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
GitHub's CSS Performance
jonrohan
1033
470k
Transcript
Ruby新⼿手读源码 覃明圆 薄荷科技
读源码style A. 通读源码(⽼老⼿手) B. 通过跟踪程序运⾏行栈读源码(新⼿手) C. 通过查bug读源码(新⼿手)
内省篇 introspection
None
• 说明: • 所有代码都在ruby 2.2版本正常⼯工作,2.2之前版 本有些⽅方法没有实现或实现有所差别。 • 由于时间关系,这部分代码不作演⽰示,建议⼤大家 打开console参照ppt⾃自⾏行实验。
对象 Object
1. 实例变量 • obj.instance_variables() 2-1. 所属的类 • obj.class() 2-2. 所属的本类
• obj.singleton_class()
类(class)
1. 继承信息、include 的模块 • klass.superclass() • klass.included_modules() • klass.ancestors() 2.
类变量 • klass.class_variables() 3. 定义的实例⽅方法 • klass.instance_methods()
变量(variables) 与 常量(constant)
• 实例变量属于对象(类也是对象) • obj.instance_variables()
• 类变量属于类体系结构(类,⼦子类,实例) • klass.class_variables() • sub_klass.class_variables()
• 局部变量属于作⽤用域 • local_variables()
• 全局变量属于全局 • global_variables()
常量 1. 所有顶级常量 • Module.constants() 2. 当前范围内的常量 • Module#constants()
⽅方法(method)
对象的⽅方法 • obj.methods() • obj.methods(false) • obj.singleton_methods()
⽅方法的可⻅见性 • obj.public_methods() • obj.protect_methods() • obj.private_methods()
• 获得⼀一个 method 对象 • obj.method(:require)
• 源码位置 • obj.method(:require).source_location
method 对象更多⽅方法 • meth.call • meth.receiver • meth.super_method
UnboundMethod • meth.unbind 转化为 UnboundMethod对象
• UnbondMethod 对象没有接收者(receiver) • unbind_meth.bind(obj) 转化为 Method 对象
⼯工具篇 tools
⼯工具提升⽣生产⼒力
• pry • pry-byebug(byebug) • pry-rails • pry-stack_explorer • pry-rescue
• web-console
• binding.pry 进⼊入runtime session
pry (1) • ls 列出当前的变量和⽅方法 • cd 进⼊入特定的程序上下⽂文环境 • whereami
当前context所在位置 • watch 跟踪某个变量,发⽣生变化时打印出来
pry (2) • show-source 查看⽅方法或者类定义的位置 • stat 查看⽅方法的信息
pry (3) • nesting 跟踪pry进⼊入的上下⽂文嵌套信息
byebug • step: ⼀一步步执⾏行下⼀一⾏行命令,或进⼊入下⼀一个⽅方 法。
pry-stack_explorer • show-stack:查看程序的运⾏行栈,深⼊入了解程序 运⾏行的过程 • frame:⾄至特定的frame • down / up:
跳转⾄至上⼀一个或下⼀一个frame
pry-rescue • rescue 命令 • cd-cause:Move to the exception that
caused this exception to happen • try-again:Re-try the code that caused this exception
web-console • 在浏览器提供 命令⾏行界⾯面 • 通过 console 调⽤用或者 异常 ⾃自动调⽤用
联系⽅方式:
[email protected]