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とblock
Search
murajun1978
February 19, 2014
Programming
78
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rubyとblock
murajun1978
February 19, 2014
Transcript
12 slides
Ruby&block
block do…end {…}
yield def foo yield end foo do puts "Hello!" end
#=> Hello!
yield def foo yield if block_given? end foo do puts
"Hello!" end #=> Hello! ! foo #=>
proc def foo &proc proc.call end proc = Proc.new do
puts "Hello!" end foo &proc #=> Hello!
proc def foo name, &proc proc.call(name) end proc = Proc.new
do |name| puts “Hello, #{name}!” end foo “Ruby”, &proc #=> Hello, Ruby!
lambda def foo &lambda lambda.call end lambda = -> {puts
“Hello!”} foo &lambda #=> Hello!
proc ͱ lambda def foo block block.call 1, 2 end
foo proc { |x, y, z| p x #=> 1 p y #=> 2 p z # => nil } def foo block block.call 1, 2 end foo lambda { |x, y, z| p x p y p z } # ArgumentError
Rails model class User < ActiveRecord::Base def admin? end end
admin = [] User.all.each do |user| admin << user if user.admin? end User.select {|user| user.admin?} User.select(&:admin?)
Rails model scope class User < ActiveRecord::Base AUTHORITY_ADMIN = “admin”
scope :admin, -> { where(authority: AUTHORITY_ADMIN) } ! def admin? end end
I can have fun coding in in Ruby
Thanks :)
More Decks by murajun1978
See All by murajun1978
変化を楽しむエンジニアリング ~ いままでとこれから ~
murajun1978
0
1.5k
How to Enjoy the Murajun’s Style
murajun1978
0
120
Building Tebukuro with Hotwire and Rails
murajun1978
0
1.6k
Zeitwerk integration in Rails 6.0
murajun1978
0
160
Efficient development with GraphQL
murajun1978
0
350
Effective Debugging Apps in VS Code
murajun1978
1
1.1k
tebukuro
murajun1978
0
160
Shinosaka.rb #17 Hands on
murajun1978
0
89
New Features in Rails 4.2
murajun1978
0
1k
Other Decks in Programming
See All in Programming
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
190
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
210
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
260
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
180
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
310
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
170
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.4k
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
130
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
240
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
140
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
3
1.7k
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
2.3k
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
340
58k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.2k
A Tale of Four Properties
chriscoyier
163
24k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
570
Optimising Largest Contentful Paint
csswizardry
37
4k
AI: The stuff that nobody shows you
jnunemaker
PRO
12
1.3k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
750
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
480
Building Adaptive Systems
keathley
44
3.3k