Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

札幌Ruby LT 惚れちゃうコード

1,289 views

Published on

Published in: Technology, Health & Medicine
  • Be the first to comment

  • Be the first to like this

札幌Ruby LT 惚れちゃうコード

  1. 1. 惚れちゃうコード 小林せかい(クックパッド, Asakusa.rb)
  2. 2. What is ? ! more smart, 
 more like Ruby
  3. 3. case 1
  4. 4. before def self.same_record?(data1, data2) return false unless data1.arg1 == data2.arg1 return false unless data1.arg2 == data2.arg2 return false unless data1.arg3 == data2.arg3 return false unless data1.arg4 == data2.arg4 true end ! !
  5. 5. after def same_record?(data1) self.arg1 == data2.arg1 && self.arg2 == data2.arg2 && self.arg3 == data2.arg3 && self.arg4 == data2.arg4 end ! ! !
  6. 6. case 2
  7. 7. before ! let(:users) { [user1, user2, user3] } ! let(:user1) { a = User.new(user_id: 111, name: ‘Taro’);a.save(validate: false)};a } ! let(:user2) { a = User.new(user_id: 222, name: ‘Jiro’);a.save(validate: false)}; a } ! # NG (return boolean) let(:user3) { User.new(user_id: 333, name: ‘Tom’).save(validate: false) }
  8. 8. after let(:users){[ User.new(user_id: 111, name: ‘Taro'). tap{|a| a.save(validate: false)}, ! User.new(user_id: 222, name: ‘Jiro'). tap{|a| a.save(validate: false)}, ]}
  9. 9. case 3
  10. 10. example ! ! ! ! 1 2 3 4 aa bb aa aa 1 2 aa bb
  11. 11. before ! def method_1(data) data.each_with_index do | datum, i| next if i == 0 datum.destroy if datum.same_value?(self) end end 1 aa 1 aa end 2 bb 2 bb ! ! ! data.first.method_1(data) 3 4 aa aa
  12. 12. after ! def method_1(data) data.each do | datum | datum.destroy if datum.same_value?(self) end end ! ! ! ! data.shift.method_1(data) 1 2 3 4 aa bb aa aa 1 2 aa bb
  13. 13. So …,
  14. 14. How many days left? 2.14
  15. 15. Let s horesase" coding
  16. 16. End ♥

×