Code@Six - Ruby 2.0

489 views

Published on

Predavanje održano 18.06.2013 na Code@Sixu.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
489
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Code@Six - Ruby 2.0

  1. 1. RUBY 2.0Pripovjedač: Nikola Šantić
  2. 2. RUBY 2.0MISIJA U MOSKVIPripovjedač: Nikola Šantić
  3. 3. Ruby je programski jezik
  4. 4. Nijedan jezik nije LOŠosim Visual Basica
  5. 5. Nijedan jezik nije LOŠosim Visual Basicai PHPa
  6. 6. Nijedan jezik nije LOŠosim Visual Basicai PHPai javascripta
  7. 7. Postoje LOŠI jezici
  8. 8. Ali Ruby je odličanStvarno
  9. 9. 11 razloga zašto je odličan
  10. 10. if (sequel == 7)print("yes!")endseries.push("Mission to Moscow")title.reverse().capitalize()1. Zagrade!if sequel == 7print "yes!"endseries.push "Mission to Moscow"title.reverse.capitalize
  11. 11. 2. if-ovi bez granicaif character == "Harris"print "MAHONEY!!!"endprint "MAHONEY!!!" if character == "Harris"unless character.russian?play_academy_themeend
  12. 12. 3. Sve je objekt"police academy".upcase=> "POLICE ACADEMY"
  13. 13. 3. Sve je objekt"police academy".upcase=> "POLICE ACADEMY"mission_to_moscow = Movie.new=> #<Movie:0x00000106f95a40>
  14. 14. 3. SVE je objekt"police academy".upcase=> "POLICE ACADEMY"19.years.ago=> Sat, 18 Jun 1994 00:55:38 UTC +00:00mission_to_moscow = Movie.new=> #<Movie:0x00000106f95a40>
  15. 15. 4. Najljepši literaliOvo je string bez posebnih znakova n/"Ovo je policijska akademija #{ 6 + 1 }"/police academy [0-9]+/ioscar_reception_date = nilus_gross = 126_247%w(Lassard Jones Tackleberry) == ["Lassard","Jones","Tackleberry"]{de: "Mission in Moskau", it: "Missione a Mosca",hu: "A rendõrakadémia Moszkvában" }
  16. 16. 5. Enumeratori(1..20).each do |i|puts iend
  17. 17. 5. Enumeratori(1..20).select{|i| i.even?}(1..20).each do |i|puts iend
  18. 18. 5. Enumeratori(1..20).select{|i| i.even?}.map{|i| "Razbojnik #{i}"}(1..20).each do |i|puts iend
  19. 19. 5. Enumeratori(1..20).select{|i| i.even?}.map{|i| "Razbojnik #{i}"}.each do |i|puts iend(1..20).each do |i|puts iend
  20. 20. 6. Zamjena dvije varijablenikad nije bila tako lakax, y = y, x
  21. 21. 7. Duck typingif mission_to_moscow.respond_to?(:remake)mission_to_moscow.remakeend
  22. 22. 8. DINAMO!"Tackleberry".methods=> [:==, :===, :eql?, :hash, :casecmp, :+, :*,:%, :[], :[]=, ...
  23. 23. 8. Dinamično programiranje"Tackleberry".methods=> [:==, :===, :eql?, :hash, :casecmp, :+, :*,:%, :[], :[]=, ...
  24. 24. 8. Dinamično programiranje"Tackleberry".methods=> [:==, :===, :eql?, :hash, :casecmp, :+, :*,:%, :[], :[]=, ...class Characterdef speak# bla blaendendjones = Character.newjones.speak
  25. 25. 8. Dinamično programiranje"Tackleberry".methods=> [:==, :===, :eql?, :hash, :casecmp, :+, :*,:%, :[], :[]=, ...class Characterdef speak# bla blaendendjones = Character.newjones.speakdef jones.make_noisesputs "beep! boop!"endjones.make_noises
  26. 26. 9. Random nasljeđivanjeclass RandomSubclass < [Array, Hash, String, Fixnum, Float].sampleend
  27. 27. 10. method_missingclass RussianAcademyProxydef initialize(academy)@academy = academyenddef do_russian_stuff# ...enddef method_missing(method, *args, &block)@academy.send(method, *args, &block)endend
  28. 28. 11. Najlakše brisanje diskaIKADrequire fileutilsFileUtils.rm_rf(/)
  29. 29. Navodno trebam pričati oRubyju 2.0
  30. 30. • Dec 1996 - 1.0• Aug 2003 - 1.8• Dec 2007 - 1.9.0• Aug 2010 - 1.9.2PovijestFEB 24th 2013 - 2.0
  31. 31. Nije strašno.Potpuno je kompatibilno s 1.9Koliko je strašno?
  32. 32. Što je novo?
  33. 33. # encoding: utf-8 više ne treba!proctooooor = "(╯°□°)╯"Default UTF-8
  34. 34. Keyword argumentswrap("Blue Oyster Bar")=> "***Blue Oyster Bar***"wrap("Blue Oyster Bar", before: "8=", after: "=>")=> "8=Blue Oyster Bar=>"
  35. 35. Keyword argumentsDosad:wrap("Blue Oyster Bar")=> "***Blue Oyster Bar***"wrap("Blue Oyster Bar", before: "8=", after: "=>")=> "8=Blue Oyster Bar=>"def wrap(string, options={})before = options[:before] || ***after = options[:after] || ***"#{before}#{string}#{after}"end
  36. 36. Keyword argumentsOdsad:wrap("Blue Oyster Bar")=> "***Blue Oyster Bar***"wrap("Blue Oyster Bar", before: "8=", after: "=>")=> "8=Blue Oyster Bar=>"def wrap(string, before: ***, after: ***)"#{before}#{string}#{after}"end
  37. 37. Module#prependclass Characterdef speakputs "Hello"endinclude RussianCultureendrussian = Character.newrussian.drink_votkarussian.speak=> "Hello"Character.ancestors=> [Character, RussianCulture, Object, Kernel, BasicObject]module RussianCulturedef drink_votkaenddef speakputs "привет"endend
  38. 38. Module#prependclass Characterdef speakputs "Hello"endprepend RussianCultureendrussian = Character.newrussian.drink_votkarussian.speak=> "привет"Character.ancestors=> [RussianCulture, Character, Object, Kernel, BasicObject]module RussianCulturedef drink_votkaenddef speakputs "привет"endend
  39. 39. Module#prependmodule RussianCulturedef speakputs "привет"superputs "прощание"endendrussian.speak=> "привет hello прощание"
  40. 40. class Stringdef russian?match(/"p{Cyrillic}+.*?.?"/ui) ? true : falseendend"привет".russian? #=> trueRefinements
  41. 41. module RussianQueryrefine String dodef russian?match(/"p{Cyrillic}+.*?.?"/ui) ? true : falseendendend"привет".respond_to?(:russian?) #=> falseusing RussianQuery"привет".russian? #=> trueRefinements
  42. 42. (1..Float::INFINITY).map{|i|i.to_s}.select{|s| s =~ /3/}.first(10)Lazy enumeratorX_X
  43. 43. (1..Float::INFINITY).lazy.map{|i|i.to_s}.select{|s| s =~ /3/}.first(10)Lazy enumerator
  44. 44. • %i{first second third} == [:first, :second, :third]• to_h• array.bsearch{|x| x >= 4}• __dir__• Bolji GCI još
  45. 45. RVM: rvm get head && rvm install 2.0.0Kako? Gdje?rbenv: rbenv install 2.0.0-p0
  46. 46. Hvala!

×