Coder Social home page Coder Social logo

scaruby's Introduction

Scala API in Ruby

https://rubygems.org/gems/scaruby

Surely it works fine.

But it mainly serves as a Ruby reference for Scala programmers.

Supported Ruby versions

Scaruby runs on Ruby 1.9.2, 1.9.3.

Gemfile

source "http://rubygems.org/"

gem 'scaruby'

Usage

See specs.

Trying on irb

bundle console
irb(main):008:0> require 'scaruby'
=> false

irb(main):009:0> Option.new(nil).is_defined
=> false
irb(main):010:0> Option.apply(nil).is_defined
=> false
irb(main):011:0> Option.new(123).is_defined
=> true

irb(main):012:0> Seq.new([1,2,3]).filter {|e| e < 2 }
=> #<Scaruby::Seq:0x9772424 @array=[1]>
irb(main):013:0> Seq.new([1,2,3]).filter {|e| e < 2 }.to_a
=> [1]
irb(main):014:0> Seq.new([1,2,3]).fold_left(0) {|z,x| z + x }
=> 6

irb(main):025:0> Map.new({123=>'abc',23=>'bc',345=>'cde'}).filter {|k,v| k.to_s.size == 3 }
=> #<Scaruby::Map:0x94afa98 @hash={123=>"abc", 345=>"cde"}>
irb(main):026:0> Map.new({123=>'abc',23=>'bc',345=>'cde'}).filter {|k,v| k.to_s.size == 3 }.to_hash
=> {123=>"abc", 345=>"cde"}

scaruby/converter might be useful.

irb(main):001:0> require 'scaruby/converter'
=> true
irb(main):002:0> 'abc'.to_option.is_defined
=> true
irb(main):003:0> 'abc'.to_option.get_or_else('zzz')
=> "abc"
irb(main):004:0> nil.to_option.is_defined
=> false
irb(main):005:0> [1,2,3].to_scaruby.foreach do |e| puts e end
1
2
3
=> [1, 2, 3]

It is also possible to extend Ruby with Scaruby.

If the method is missing, the method in Scaruby will be invoked.

In this case, the methods already defined (i.e. flat_map, find and so on) are never replaced.

irb(main):015:0> require 'scaruby/core_ext'
=> true
irb(main):016:0> 1.upto(5).filter {|i| i < 3 }
=> [1, 2]
irb(main):020:0> 1.upto(5).filter {|i| i < 3 }.foreach do |i|
irb(main):021:1*   puts i
irb(main):022:1> end
1
2
=> [1, 2]

irb(main):027:0> {123=>'abc',23=>'bc',345=>'cde'}.filter {|k,v| k.to_s.size == 3 }
=> {123=>"abc", 345=>"cde"}

Build Status

Build Status

License

MIT License

https://github.com/seratch/scaruby/blob/master/LICENSE.txt

scaruby's People

Contributors

seratch avatar

Stargazers

 avatar Angus H. avatar nmccready avatar Taro Nagasawa avatar  avatar

Watchers

 avatar Toshiyuki Takahashi avatar James Cloos avatar  avatar

Forkers

nmccready

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.