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.

えっ、なにそれこわい

2,208 views

Published on

オブジェクト倶楽部2010夏イベント
ぴちぴち若人トラック
http://www.objectclub.jp/event/2010summer/

Published in: Technology
  • Be the first to comment

  • Be the first to like this

えっ、なにそれこわい

  1. 1. 2010 2010/07/16 @kei_s
  2. 2. ( ) id:kei-s, @kei_s RubyKaigi2010
  3. 3. ( ) id:kei-s, @kei_s RubyKaigi2010
  4. 4. I like ... Ruby JavaScript ( Squarepusher ) ( )
  5. 5. :
  6. 6. :
  7. 7. Ruby JavaScript Ruby JavaScript Ajax Ruby
  8. 8. Ruby JavaScript Ruby JavaScript
  9. 9. 1. Ajax
  10. 10. JavaScript ( with jQuery ) var user = {name: ‘kei_s’}; user.age = 26; $.post(‘/user’, {data: user});
  11. 11. Ruby ( with Sinatra ) post ‘/user’ do user = params puts user.age ‘ok’ end #=>
  12. 12. Ruby ( with Sinatra ) post ‘/user’ do user = params puts user.age ‘ok’ end #=> NoMethodError: undefined method `age'
  13. 13. Ruby ( with Sinatra ) post ‘/user’ do user = params puts user.age ‘ok’ end #=> NoMethodError: undefined method `age'
  14. 14. Ruby ( with Sinatra ) post ‘/user’ do user = params # puts user.age puts user[‘age’] ‘ok’ end #=> 26
  15. 15. JavaScript hash.key //=> value hash[‘key’] //=> value Ruby hash.key #=> key hash[‘key’] #=> value
  16. 16. 2.
  17. 17. Ruby users = [ {'age'=>22},{'age'=>26},{'age'=>31} ] users.select{|user| user[‘age’] < 30 }.size #=> 2
  18. 18. JavaScript var users = [ {'age': 22},{'age': 26},{'age': 31} ]; users.filter(function(user){ user.age < 30; }).length; //=>
  19. 19. JavaScript var users = [ {'age': 22},{'age': 26},{'age': 31} ]; users.filter(function(user){ user.age < 30; }).length; //=> 0
  20. 20. JavaScript var users = [ {'age': 22},{'age': 26},{'age': 31} ]; users.filter(function(user){ user.age < 30; }).length; //=> 0
  21. 21. JavaScript var users = [ {'age': 22},{'age': 26},{'age': 31} ]; users.filter(function(user){ //user.age < 30; return user.age < 30; }).length; //=> 2
  22. 22. JavaScript function(){ v; } //=> undefined function(){ return v; } //=> v Ruby def func() v; end #=> v def func() return v; end #=> v
  23. 23. 3.
  24. 24. JavaScript ( with jQuery ) $.get(‘/user.json’, function(response){ console.log( response ); } );
  25. 25. Ruby ( with Typhoeus ) hydra = Typhoues::Hydra.new request= Typhoeus::Request.new(‘/user.json’) request.on_complete do |response| puts response.body end hydra.queue request hydra.run
  26. 26. JavaScript ( with jQuery ) $.get(‘/user.json’, function(response){ console.log( response ); } );
  27. 27. JavaScript ( with jQuery ) Users.prototype.store = function(response) { this.responses.push(response); }; var users = new Users(); $.get(‘/user1.json’,users.store); $.get(‘/user2.json’,users.store);
  28. 28. Ruby ( with Typhoeus ) def Users.store(response) @responses << response end users = Users.new request1 = Typhoeus::Request.new(‘/user1.json’) request2 = Typhoeus::Request.new(‘/user2.json’) request1.on_complete(users.store) request2.on_complete(users.store) hydra.queue request1 hydra.queue request2 hydra.run #=>
  29. 29. Ruby ( with Typhoeus ) def Users.store(response) @responses << response end users = Users.new request1 = Typhoeus::Request.new(‘/user1.json’) request2 = Typhoeus::Request.new(‘/user2.json’) request1.on_complete(users.store) request2.on_complete(users.store) hydra.queue request1 hydra.queue request2 hydra.run #=> ArgumentError: wrong number of arguments (0 for 1)
  30. 30. Ruby ( with Typhoeus ) request.on_complete(users.store) #=> Users#store #=> ArgumentError: wrong number of arguments (0 for 1)
  31. 31. Ruby ( with Typhoeus ) def Users.store(response) @responses << response end users = Users.new request.on_complete do |response| users.store(response) end #=> OK
  32. 32. Ruby ( with Typhoeus ) def Users.store(response) @responses << response end users = Users.new request.on_complete &users.method(:store) #=> OK request.on_complete = users.method(:store) #=> OK (only for Typhoeus::Request)
  33. 33. JavaScript object.func //=> Function Ruby object.method(:func) #=> Method object.method(:func).to_proc #=> Proc
  34. 34. Ruby JavaScript =>
  35. 35. http://www.flickr.com/photos/magisterludi/405224443/
  36. 36. http://www.flickr.com/photos/delusionary/478351622/
  37. 37. http://www.flickr.com/photos/midgley/3687327166/
  38. 38. http://www.flickr.com/photos/hand-nor-glove/563554215/
  39. 39. A Jedi Master said ...
  40. 40. http://twitpic.com/22iyix
  41. 41. “Control, control. You must learn control.”
  42. 42. “Control, control. You must learn control.”
  43. 43. “Control, control. You must learn control.”
  44. 44. http://www.flickr.com/photos/fazen/427962176/
  45. 45. http://www.flickr.com/photos/hand-nor-glove/626648592/
  46. 46. http://www.flickr.com/photos/magisterludi/405224443/
  47. 47. “Control, control. You must learn control.”
  48. 48.

×