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-refinements
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
to4iki
September 07, 2014
Programming
97
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ruby-refinements
http://ruby-doc.org/core-2.1.1/doc/syntax/refinements_rdoc.html
to4iki
September 07, 2014
More Decks by to4iki
See All by to4iki
Claude Code の活用事例
to4iki
0
200
Swift Concurrencyを利用したUIViewController表示の排他制御の実装
to4iki
0
3.8k
ケースに応じたUICollectionViewのレイアウト実装パターン
to4iki
1
5.9k
ビューインプレッションの計測方法
to4iki
1
1.2k
秘伝の `gitconfig`
to4iki
1
470
Abema iOS Architecture
to4iki
12
3.6k
timetable-bot
to4iki
0
15k
BLoC Pattern Introduction with Swift
to4iki
2
1.4k
nel
to4iki
0
200
Other Decks in Programming
See All in Programming
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
270
ジョジョの世界をXRで再現する
mofurune
0
160
Workers Cache を知る
syumai
0
360
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
190
APNsからLive Activityを開始する話
yumnumm
0
170
Next.js: The final boss of Web Performance
guaca
0
250
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
180
phperだってパンチカードでコーディングしたい
o0h
PRO
0
330
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
2
540
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
Featured
See All Featured
Test your architecture with Archunit
thirion
2
2.4k
Site-Speed That Sticks
csswizardry
13
1.6k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
A better future with KSS
kneath
240
18k
Chasing Engaging Ingredients in Design
codingconduct
0
360
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
How to train your dragon (web standard)
notwaldorf
96
6.9k
Typedesign – Prime Four
hannesfritz
42
3.2k
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
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.