$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. A  port  of  Ruby  core-­‐lib  to  JS   •  String,

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

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

    Float jjjj.............................. Integer .................... Kernel ... Matchdata ..................... Numeric ....................... Range ...................... Regexp jj...................... String jjjjjjjjjjjjj................................ ...........................
  4. 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  
  5. str = R("a")
 str.capitalize() 
 .upto('C’) .to_a() .join(', ') .ljust(10,

    ‘-’)
 .to_native(); #=> string
 #=> ’A, B, C---'
  6. Wrapper   class RubyJS.Fixnum @include RubyJS.Comparable
 
 constructor: (@__native__) ->

    odd: ->
 @__native__ % 2 != 0
 
 next: ->
 new R.Fixnum(@__native__ + 1)  
  7. Ruby   arr = %w(looks feels acts) 
 arr.map {|w|

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

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

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

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

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

    R.proc(’ljust’, 35) ) .join(", ") 
 .concat(" like Ruby")
 .center(35, '-')    
  13. arr = ['looks', 'feels', 'acts'];
 
 str = _.map(arr, (w)

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

    -> w.capitalize() )
 .join(", ") 
 .concat(" like Ruby")
 .center(35, '-')
 '---Looks, Feels, Acts like Ruby---’  
  15. 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">    
  16. 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”)  
  17. 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  
  18. One  chain   arr = R.w('looks feels acts') 
 arr.map((w)

    -> w.capitalize() )
 .join(", ") 
 .concat(" like Ruby")
 .center(35, '-')
  
  19. Roadmap   •  Move  from  CoffeeScript  to  JavaScript   • 

    RubyJS  corelib   – Time,  Hash,  Date   •  RubyJS  corelib-­‐lite   – remove  some  rubyisms   – simplify