Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

Attendees from Matsue office — @nacl — @yukihiro_matz — @shugomaeda — @takaokouji — @nobyuki — @nari3 — @yhara (me)

Slide 3

Slide 3 text

http://www.netlab.jp/recruit

Slide 4

Slide 4 text

My current project — github:yhara/boom — Toy language with type inference — Will resume it as soon as I quit Ingress

Slide 5

Slide 5 text

Recent interests 1. "Ruby and Patten Match" 2. "Ideal way to map a hash" 3. "Opal the Ruby to JS compiler"

Slide 6

Slide 6 text

1. Ruby and Patten Match

Slide 7

Slide 7 text

Ruby HAS pattern match (via gem) — pattern-match gem (@k_tsj) — patm gem (@todesking, limited but faster) — egison gem (@__Egi, RubyKaigi Day 1)

Slide 8

Slide 8 text

ɹ Pattern Match is like Regexp for Objects

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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}" } }

Slide 11

Slide 11 text

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 } }

Slide 12

Slide 12 text

Try it now. $ gem install pattern-match require 'pattern-match' match(1){ with(x){ p x } } github:k-tsj/pattern-match

Slide 13

Slide 13 text

2. Ideal way to map a hash

Slide 14

Slide 14 text

My proposals accepted — #1961 __dir__ — #4890 Enumerable#lazy — #6670 String#lines should return array and one more challenge:

Slide 15

Slide 15 text

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]]

Slide 16

Slide 16 text

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}

Slide 17

Slide 17 text

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}

Slide 18

Slide 18 text

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, ...???

Slide 19

Slide 19 text

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?

Slide 20

Slide 20 text

3. Opal the Ruby to JS compiler

Slide 21

Slide 21 text

http://opalrb.org/

Slide 22

Slide 22 text

http://opalrb.org/ — Compiler from Ruby to JavaScript — Some difference, but mostly Ruby — String is immutable, etc.

Slide 23

Slide 23 text

Why Opal matters #1 JavaScript x HTML5 JavaScript x WebSocket JavaScript x WebRTC JavaScript x Mobile ...

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

Why Opal matters #2 — Two languages [Client] [Server] JavaScript ---> Rails(Ruby) <---

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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)

Slide 28

Slide 28 text

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"

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Yeahrb Demo $ gem i yeah $ yeah new hello $ cd hello $ yeah serve $ open http://localhost:1234 $ vi code/game.rb

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

Yeahrb Demo Feels like so Ruby that you never want to go back to JavaScript :-)

Slide 33

Slide 33 text

ۙگใࠂ: I'm enjoying programming.