$30 off During Our Annual Pro Sale. View Details »

RubyJS at rubyconf.tw

hasclass
December 07, 2012

RubyJS at rubyconf.tw

lightning talk

hasclass

December 07, 2012
Tweet

More Decks by hasclass

Other Decks in Programming

Transcript

  1. RubyJS  alpha  
    www.rubyjs.org  
    twi5er.com/hasclass  
     
     

    View Slide

  2. 50  slides  in  5  minutes  

    View Slide

  3. View Slide

  4. View Slide

  5. A  port  of  Ruby  core-­‐lib  to  JS  
    •  String,  Regexp,  MatchData  
    •  Array,  Enumerable,  Enumerator  
    •  Numeric  (Integer/Fixnum,  Float)  
    •  Range  
    •  Time,  Hash  coming  soon  

    View Slide

  6. JS  Methods  
    Array jjjjjjjjjjjjj
    Enumerable
    Fixnum
    Float jjjj
    Integer
    Kernel
    Matchdata
    Numeric
    Range
    Regexp jj
    String jjjjjjjjjjjjj

    View Slide

  7. RubyJS  Methods  
    Array jjjjjjjjjjjjj.................................
    ............................
    Enumerable ..............................................
    Fixnum ...........................
    Float jjjj..............................
    Integer ....................
    Kernel ...
    Matchdata .....................
    Numeric .......................
    Range ......................
    Regexp jj......................
    String jjjjjjjjjjjjj................................
    ...........................

    View Slide

  8. Compliant  to  Ruby  
    No  surprises..  
    Rubinius  Rubyspecs  ported  to  JS  

    View Slide

  9. str = "a"

     

    View Slide

  10. str = R("a”) #=> R.String

     

    View Slide

  11. str = R("a")

    str.capitalize() #=> R.String

    #=> A

    View Slide

  12. str = R("a")

    str.capitalize() 

    .upto('C') #=> R.Enumerator

    View Slide

  13. str = R("a")

    str.capitalize() 

    .upto('C’)

    .each_cons(2, function (a,b) {

    R.puts("#{a} to the #{b}")
    })

    # A to the B

    # B to the C
     

    View Slide

  14. str = R("a")

    str.capitalize() 

    .upto('C’)

    .to_a() #=> R.Array

    #=> [A, B, C]

    View Slide

  15. str = R("a")

    str.capitalize() 

    .upto('C’)
    .to_a()
    .join(', ') #=> R.String
    #=> ’A, B, C'

    View Slide

  16. str = R("a")

    str.capitalize() 

    .upto('C’)
    .to_a()
    .join(', ')
    .ljust(10, ‘-’) #=> R.String
    #=> ’A, B, C---'

    View Slide

  17. str = R("a")

    str.capitalize() 

    .upto('C’)
    .to_a()
    .join(', ')
    .ljust(10, ‘-’)

    .to_native(); #=> string

    #=> ’A, B, C---'

    View Slide

  18. RubyJS  objects  are  wrappers  
    Around  naMve  JS  objects  

    View Slide

  19. Wrapper  
    class RubyJS.Fixnum
    @include RubyJS.Comparable


    constructor: (__native__) ->
    @__native__ = __native__;


    #=> new R.Fixnum(2)  

    View Slide

  20. Wrapper  
    class RubyJS.Fixnum
    @include RubyJS.Comparable


    constructor: (@__native__) ->
    odd: ->

    @__native__ % 2 != 0

     

    View Slide

  21. Wrapper  
    class RubyJS.Fixnum
    @include RubyJS.Comparable


    constructor: (@__native__) ->
    odd: ->

    @__native__ % 2 != 0


    next: ->

    new R.Fixnum(@__native__ + 1)  

    View Slide

  22. PorMng  Ruby  Code  to  JS  

    View Slide

  23. Ruby  
    arr = %w(looks feels acts)

    arr.map {|w| w.capitalize }

    .join(", ") 

    .concat(" like Ruby")

    .center(35, '-')
    '---Looks, Feels, Acts like Ruby---’  

    View Slide

  24. RubyJS  
    arr = R.w('looks feels acts') 


     

    View Slide

  25. RubyJS  
    arr = R.w('looks feels acts') 


    arr.map {|w| w.capitalize }

     

    View Slide

  26. RubyJS  
    arr = R.w('looks feels acts') 


    arr.map((w) -> w.capitalize() )




    View Slide

  27. RubyJS  
    arr = R.w('looks feels acts') 


    arr.map((w) -> w.capitalize() )

    .join(", ") 

    .concat(" like Ruby")

    .center(35, '-')

    '---Looks, Feels, Acts like Ruby---’  

    View Slide

  28. Ruby  
    arr = %w(looks feels acts) 


    arr.map {|w| w.capitalize }

    .join(", ") 

    .concat(" like Ruby")

    .center(35, '-’) 

    '---Looks, Feels, Acts like Ruby---’  

    View Slide

  29. RubyJS  
    arr = R.w('looks feels acts') 


    arr.map((w) -> w.capitalize() )

    .join(", ") 

    .concat(" like Ruby")

    .center(35, '-')

    '---Looks, Feels, Acts like Ruby---’  

    View Slide

  30. Symbol#to_proc  
    arr = R.w('looks feels acts') 


    arr.map( R.proc('capitalize’) )
    .join(", ") 

    .concat(" like Ruby")

    .center(35, '-')  
     

    View Slide

  31. Symbol#to_proc  
    arr = R.w('looks feels acts') 


    arr.map( R.proc(’ljust’, 35) )
    .join(", ") 

    .concat(" like Ruby")

    .center(35, '-')  
     

    View Slide

  32. But  I  can  do  with  library  x,  y  ,z  

    View Slide

  33. arr = ['looks', 'feels', 'acts'];


    str = _.map(arr, (w) ->

    S(w).capitalize().s;

    ).join(', ')


    str += ' like Ruby’;

    S(str).pad(15, '-');

     

    View Slide

  34. RubyJS  
    arr = R.w('looks feels acts') 


    arr.map((w) -> w.capitalize() )

    .join(", ") 

    .concat(" like Ruby")

    .center(35, '-')

    '---Looks, Feels, Acts like Ruby---’  

    View Slide

  35. Benefits  

    View Slide

  36. One  dependency  




     

    View Slide

  37. One  dependency  





     <br/>  <br/>

    View Slide

  38. One  API  
    _.map([], (w) -> )

    _.chain(arr).(...).value()

    S("foo").capitalize().s

    moment().format('L')

     

    View Slide

  39. One  API  
    R( [1] ).map().to_native()

    R( [2] ).map().reject().to_native()

    R("foo").capitalize().to_native()

    R(new Date(…)).strftime(“%y-%m-%d”)  

    View Slide

  40. One  chain  
    arr = ['looks', 'feels', 'acts']

    str = _.map(arr, (w) ->
    S(w).capitalize().s
    ).join(', ’)

    str += " not like Ruby”

    S(str).pad(str, 35, '-').s  

    View Slide

  41. One  chain  
    arr = R.w('looks feels acts') 

    arr.map((w) -> w.capitalize() )

    .join(", ") 

    .concat(" like Ruby")

    .center(35, '-')

     

    View Slide

  42. One  documentaMon  

    View Slide

  43. One  documentaMon  

    View Slide

  44. 20  kbytes  
    minified  and  gzipped  

    View Slide

  45. It  scales  

    View Slide

  46. Dual-­‐license  
    •  AGPL    
    •  Commercial  license    

    View Slide

  47. Booh  

    View Slide

  48. Booh  

    View Slide

  49. Should  I  open  source  it?  

    View Slide

  50. View Slide

  51. DO  IT  

    View Slide

  52. RubyJS  is  now  MIT  License  

    View Slide

  53. Happy  hacking  

    View Slide

  54. Roadmap  
    •  Move  from  CoffeeScript  to  JavaScript  
    •  RubyJS  corelib  
    – Time,  Hash,  Date  
    •  RubyJS  corelib-­‐lite  
    – remove  some  rubyisms  
    – simplify  

    View Slide

  55. RubyJS.org  
    twi5er.com/hasclass  
     

    View Slide