RubyJS at rubyconf.tw

180293b3d2d1977bd7dee2557f317cfd?s=47 hasclass
December 07, 2012

RubyJS at rubyconf.tw

lightning talk

180293b3d2d1977bd7dee2557f317cfd?s=128

hasclass

December 07, 2012
Tweet

Transcript

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

  2. 50  slides  in  5  minutes  

  3. None
  4. None
  5. A  port  of  Ruby  core-­‐lib  to  JS   •  String,

     Regexp,  MatchData   •  Array,  Enumerable,  Enumerator   •  Numeric  (Integer/Fixnum,  Float)   •  Range   •  Time,  Hash  coming  soon  
  6. JS  Methods   Array jjjjjjjjjjjjj Enumerable Fixnum Float jjjj Integer

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

    Float jjjj.............................. Integer .................... Kernel ... Matchdata ..................... Numeric ....................... Range ...................... Regexp jj...................... String jjjjjjjjjjjjj................................ ...........................
  8. Compliant  to  Ruby   No  surprises..   Rubinius  Rubyspecs  ported

     to  JS  
  9. str = "a"
  

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

  11. str = R("a")
 str.capitalize() #=> R.String
 #=> A

  12. str = R("a")
 str.capitalize() 
 .upto('C') #=> R.Enumerator

  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  
  14. str = R("a")
 str.capitalize() 
 .upto('C’)
 .to_a() #=> R.Array
 #=>

    [A, B, C]
  15. str = R("a")
 str.capitalize() 
 .upto('C’) .to_a() .join(', ') #=>

    R.String #=> ’A, B, C'
  16. str = R("a")
 str.capitalize() 
 .upto('C’) .to_a() .join(', ') .ljust(10,

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

    ‘-’)
 .to_native(); #=> string
 #=> ’A, B, C---'
  18. RubyJS  objects  are  wrappers   Around  naMve  JS  objects  

  19. Wrapper   class RubyJS.Fixnum @include RubyJS.Comparable
 
 constructor: (__native__) ->

    @__native__ = __native__; 
 
 #=> new R.Fixnum(2)  
  20. Wrapper   class RubyJS.Fixnum @include RubyJS.Comparable
 
 constructor: (@__native__) ->

    odd: ->
 @__native__ % 2 != 0
  
  21. Wrapper   class RubyJS.Fixnum @include RubyJS.Comparable
 
 constructor: (@__native__) ->

    odd: ->
 @__native__ % 2 != 0
 
 next: ->
 new R.Fixnum(@__native__ + 1)  
  22. PorMng  Ruby  Code  to  JS  

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

    w.capitalize }
 .join(", ") 
 .concat(" like Ruby")
 .center(35, '-') '---Looks, Feels, Acts like Ruby---’  
  24. RubyJS   arr = R.w('looks feels acts') 
 
  

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

    {|w| w.capitalize }
  
  26. RubyJS   arr = R.w('looks feels acts') 
 
 arr.map((w)

    -> w.capitalize() )
 
 
 

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

    -> w.capitalize() )
 .join(", ") 
 .concat(" like Ruby")
 .center(35, '-')
 '---Looks, Feels, Acts like Ruby---’  
  28. Ruby   arr = %w(looks feels acts) 
 
 arr.map

    {|w| w.capitalize }
 .join(", ") 
 .concat(" like Ruby")
 .center(35, '-’) 
 '---Looks, Feels, Acts like Ruby---’  
  29. RubyJS   arr = R.w('looks feels acts') 
 
 arr.map((w)

    -> w.capitalize() )
 .join(", ") 
 .concat(" like Ruby")
 .center(35, '-')
 '---Looks, Feels, Acts like Ruby---’  
  30. Symbol#to_proc   arr = R.w('looks feels acts') 
 
 arr.map(

    R.proc('capitalize’) ) .join(", ") 
 .concat(" like Ruby")
 .center(35, '-')    
  31. Symbol#to_proc   arr = R.w('looks feels acts') 
 
 arr.map(

    R.proc(’ljust’, 35) ) .join(", ") 
 .concat(" like Ruby")
 .center(35, '-')    
  32. But  I  can  do  with  library  x,  y  ,z  

  33. arr = ['looks', 'feels', 'acts'];
 
 str = _.map(arr, (w)

    ->
 S(w).capitalize().s;
 ).join(', ')
 
 str += ' like Ruby’;
 S(str).pad(15, '-');
  
  34. RubyJS   arr = R.w('looks feels acts') 
 
 arr.map((w)

    -> w.capitalize() )
 .join(", ") 
 .concat(" like Ruby")
 .center(35, '-')
 '---Looks, Feels, Acts like Ruby---’  
  35. Benefits  

  36. One  dependency   <script src="/es5shims.js"/>
 <script src="/underscore-1.3.min.js"/>
 <script src="/stringjs-0.9.9.js"/>
 <script

    src="/momentjs-1.5.1.js"/>
 <script src="/custom_functions.js"/>  
  37. One  dependency   <script src="/es5shims.js"/>
 <script src="/underscore-1.3.min.js"/>
 <script src="/stringjs-0.9.9.js"/>
 <script

    src="/momentjs-1.5.1.js"/>
 <script src="/custom_functions.js"/> <script src="/ruby.js">    
  38. One  API   _.map([], (w) -> ) 
 _.chain(arr).(...).value()
 S("foo").capitalize().s


    moment().format('L')
  
  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”)  
  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  
  41. One  chain   arr = R.w('looks feels acts') 
 arr.map((w)

    -> w.capitalize() )
 .join(", ") 
 .concat(" like Ruby")
 .center(35, '-')
  
  42. One  documentaMon  

  43. One  documentaMon  

  44. 20  kbytes   minified  and  gzipped  

  45. It  scales  

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

     
  47. Booh  

  48. Booh  

  49. Should  I  open  source  it?  

  50. None
  51. DO  IT  

  52. RubyJS  is  now  MIT  License  

  53. Happy  hacking  

  54. Roadmap   •  Move  from  CoffeeScript  to  JavaScript   • 

    RubyJS  corelib   – Time,  Hash,  Date   •  RubyJS  corelib-­‐lite   – remove  some  rubyisms   – simplify  
  55. RubyJS.org   twi5er.com/hasclass