Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ruby-refinements
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
to4iki
September 07, 2014
Programming
0
81
ruby-refinements
http://ruby-doc.org/core-2.1.1/doc/syntax/refinements_rdoc.html
to4iki
September 07, 2014
Tweet
Share
More Decks by to4iki
See All by to4iki
Claude Code の活用事例
to4iki
0
150
Swift Concurrencyを利用したUIViewController表示の排他制御の実装
to4iki
0
3.5k
ケースに応じたUICollectionViewのレイアウト実装パターン
to4iki
1
5.3k
ビューインプレッションの計測方法
to4iki
1
1.1k
秘伝の `gitconfig`
to4iki
1
460
Abema iOS Architecture
to4iki
12
3.5k
timetable-bot
to4iki
0
15k
BLoC Pattern Introduction with Swift
to4iki
2
1.3k
nel
to4iki
0
170
Other Decks in Programming
See All in Programming
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.5k
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
0
910
dchart: charts from deck markup
ajstarks
3
990
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
120
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
990
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
180
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
Fragmented Architectures
denyspoltorak
0
150
CSC307 Lecture 05
javiergs
PRO
0
500
Patterns of Patterns
denyspoltorak
0
1.4k
Featured
See All Featured
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
90
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
63
Code Review Best Practice
trishagee
74
20k
4 Signs Your Business is Dying
shpigford
187
22k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
54
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
430
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Designing for humans not robots
tammielis
254
26k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
Transcript
Ruby2.1 Refinements Λ৮ͬͯΈͨ Toshiki Takezawa @to4iki
What is Refinements
refinement: ચ࿅, վળ
“ࢦఆͨ͠moduleͷதͰ͚ͩɺ ಛఆͷclassͷmethod Λࠩ͠ସ͑Δػೳ”
open class
RubyStringͳͲͷbuiltin class ΛؚΊطଘͷclassmethodΛ Ճɾ্ॻ͖͢Δ͜ͱ͕Ͱ͖Δ
class String def hello
"#{self} hello!" end end puts 'hoge'.hello #=> 'hoge hello!' puts 'fuga'.hello #=> 'fuga hello!'
Monkey Patch
open classͰطଘͷmethod Λஔ͖͑Δ͜ͱ
class String def length
5 end define_method :to_i, -‐> { "#{self} convert number" } end puts 'a'.length #=> 5 puts 'javascript'.length #=> 5 puts '0'.to_i #=> '0 convert number' puts 'hoge'.to_i #=> 'hoge convert number'
powerful!! but danger!!
طଘclassΛࢥ͍ͷ··मਖ਼Ͱ͖Δརศੑ ϧʔϧΛഁյͯ͠͠·͏ةݥੑ programશମʹӨڹΛ༩͑ͯ͠·͏ةݥੑ
it is a turn of refinements!
Demo
ex. Ϣʔβ͕࿈ଓͰϩάΠϯ͠ ͍ͯΔ͔Ͳ͏͔ΛΓ͍ͨ࣌
module TimeExtensions refine Time do
def changed_date? self.beginning_of_day < Time.zone.now.beginning_of_day end end end class User < ActiveRecord::Base using TimeExtensions def login! if self.login_at.changed_date? # add login bonus end end end
“Ruby܅Λ৴པ͢Δɻ Ruby܅Λผͷ͋ΔϓϩάϥϚͱͯ͠ѻ͏ɻ RubyϝλϓϩάϥϛϯάͷΑ͏ͳڧྗͳྗΛ༩͑Δɻ ͨͩ͠ɺେ͍ͳΔྗʹɺେ͍ͳΔ͕͏͜ͱΛ Ε͍͚ͯͳ͍” -ʮϝλϓϩάϥϛϯάRubyʯংจΑΓ
Thanks.