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とblock
Search
murajun1978
February 19, 2014
Programming
0
55
Rubyとblock
murajun1978
February 19, 2014
Tweet
Share
More Decks by murajun1978
See All by murajun1978
Building Tebukuro with Hotwire and Rails
murajun1978
0
1.2k
Zeitwerk integration in Rails 6.0
murajun1978
0
100
Efficient development with GraphQL
murajun1978
0
290
Effective Debugging Apps in VS Code
murajun1978
1
880
tebukuro
murajun1978
0
110
Shinosaka.rb #17 Hands on
murajun1978
0
43
New Features in Rails 4.2
murajun1978
0
900
shinosakarb #11 Rails 4 Pattenrs
murajun1978
1
120
FactoryGirl LT
murajun1978
1
66
Other Decks in Programming
See All in Programming
[JAWS-UG横浜 #80] うわっ…今年のServerless アップデート、少なすぎ…?
maroon1st
0
110
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
1
450
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
420
Rubyでつくるパケットキャプチャツール
ydah
0
170
Scaling your build logic
antalmonori
1
100
Fibonacci Function Gallery - Part 2
philipschwarz
PRO
0
210
Lookerは可視化だけじゃない。UIコンポーネントもあるんだ!
ymd65536
1
130
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
2.2k
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
300
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
0
150
Beyond ORM
77web
11
1.6k
functionalなアプローチで動的要素を排除する
ryopeko
1
220
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
113
50k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Speed Design
sergeychernyshev
25
740
Building Applications with DynamoDB
mza
93
6.2k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Designing for humans not robots
tammielis
250
25k
Visualization
eitanlees
146
15k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Transcript
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 :)