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.1k
Zeitwerk integration in Rails 6.0
murajun1978
0
100
Efficient development with GraphQL
murajun1978
0
280
Effective Debugging Apps in VS Code
murajun1978
1
870
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
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
103 Early Hints
sugi_0000
1
230
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
130
Exploring: Partial and Independent Composables
blackbracken
0
100
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
6
1.2k
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
130
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
330
命名をリントする
chiroruxx
1
410
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
450
Featured
See All Featured
Become a Pro
speakerdeck
PRO
26
5k
Gamification - CAS2011
davidbonilla
80
5.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Scaling GitHub
holman
458
140k
The Cult of Friendly URLs
andyhume
78
6.1k
Side Projects
sachag
452
42k
Fireside Chat
paigeccino
34
3.1k
We Have a Design System, Now What?
morganepeng
51
7.3k
Optimising Largest Contentful Paint
csswizardry
33
3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
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 :)