Recent Updates (近況報告)

26e1ba9a02729b2d6013604135221aae?s=47 yhara
September 21, 2014

Recent Updates (近況報告)

2014/09/21 RubyHiroba2014

26e1ba9a02729b2d6013604135221aae?s=128

yhara

September 21, 2014
Tweet

Transcript

  1. ۙگใࠂ (Latest News) ɹ Yutaka HARA ωοτϫʔΫ Ԡ༻௨৴ݚڀॴ 2014/09/21 RubyHiroba2014

  2. Attendees from Matsue office — @nacl — @yukihiro_matz — @shugomaeda

    — @takaokouji — @nobyuki — @nari3 — @yhara (me)
  3. http://www.netlab.jp/recruit

  4. My current project — github:yhara/boom — Toy language with type

    inference — Will resume it as soon as I quit Ingress
  5. Recent interests 1. "Ruby and Patten Match" 2. "Ideal way

    to map a hash" 3. "Opal the Ruby to JS compiler"
  6. 1. Ruby and Patten Match

  7. Ruby HAS pattern match (via gem) — pattern-match gem (@k_tsj)

    — patm gem (@todesking, limited but faster) — egison gem (@__Egi, RubyKaigi Day 1)
  8. ɹ Pattern Match is like Regexp for Objects

  9. Match regexp against string ʮIf the string is like thisʯ

    str = "add 1 2" if str =~ /add (\d+) (\d+)/ puts "Add #{$1} and #{$2}" end
  10. Match pattern against array ʮIf the array is like thisʯ

    require 'pattern-match' ary = [:add, 1, 2] match(ary){ with(_[:add, x, y]){ puts "Add #{x} and #{y}" } }
  11. Match pattern against your class class Book # has :title,

    :price ... def self.deconstruct(val) accept_self_instance_only(val) return [val.title, val.price] end end book = Book.new("Programming Ruby", 3400) match(book){ with(Book.(/Ruby/, 0..5000)) { p book } }
  12. Try it now. $ gem install pattern-match require 'pattern-match' match(1){

    with(x){ p x } } github:k-tsj/pattern-match
  13. 2. Ideal way to map a hash

  14. My proposals accepted — #1961 __dir__ — #4890 Enumerable#lazy —

    #6670 String#lines should return array and one more challenge:
  15. Current hash.map — How to convert {:a => 1, :b

    => 2} into {"a" => 1, "b" => 2} h = {:a => 1, :b => 2} pairs = h.map{|k, v| [k.to_s, v] } #=> [["a", 1], ["b", 2]]
  16. Hash#[] h = {a: 1, b: 2} pairs = h.map{|k,

    v| [k.to_s, v] } #=> [["a", 1], ["b", 2]] Hash[pairs] #=> {"a" => 1, "b" => 2}
  17. Enumerable#to_h (Ruby >= 2.1) h = {a: 1, b: 2}

    pairs = h.map{|k, v| [k.to_s, v] } #=> [["a", 1], ["b", 2]] pairs.to_h #=> {"a" => 1, "b" => 2}
  18. Ideal way h = {a: 1, b: 2} h.xxxxxx{|k, v|

    [k.to_s, v] } #=> {"a" => 1, "b" => 2} xxxxxx == hash_map, map_hash, hash_by, morph, apply, map_kv, ...???
  19. Join bugs.ruby-lang.org — Feature #10208: Passing block to Enumerable#to_h —

    Feature #6669: A method like Hash#map but returns hash We need a good name :-( Any ideas?
  20. 3. Opal the Ruby to JS compiler

  21. http://opalrb.org/

  22. http://opalrb.org/ — Compiler from Ruby to JavaScript — Some difference,

    but mostly Ruby — String is immutable, etc.
  23. Why Opal matters #1 JavaScript x HTML5 JavaScript x WebSocket

    JavaScript x WebRTC JavaScript x Mobile ...
  24. Why Opal matters #1 Ruby(Opal) x HTML5 Ruby(Opal) x WebSocket

    Ruby(Opal) x WebRTC Ruby(Opal) x Mobile ...
  25. Why Opal matters #2 — Two languages [Client] [Server] JavaScript

    ---> Rails(Ruby) <---
  26. Why Opal matters #2 — One language! [Client] [Server] Opal(Ruby)

    ---> Rails(Ruby) <---
  27. One language for C/S — No context switch — Share

    logic among C/S (validation, etc.) — Pre-render view on the server side cf. Rendr, Meteor (Node.js)
  28. Related products Check it out! — For #1: github:yeahrb/yeah "Practical

    Ruby video game framework" — For #2: github:voltrb/volt "A ruby web framework where your ruby runs on both server and client"
  29. None
  30. Yeahrb Demo $ gem i yeah $ yeah new hello

    $ cd hello $ yeah serve $ open http://localhost:1234 $ vi code/game.rb
  31. Yeahrb Demo code/game.rb: class Hello1 < Game def setup end

    def update(elapsed) display.fill_color = C[255,255,255] display.fill_rectangle(V[0,0], display.size) end end
  32. Yeahrb Demo Feels like so Ruby that you never want

    to go back to JavaScript :-)
  33. ۙگใࠂ: I'm enjoying programming.