Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seratch/scaruby
Scala API in Ruby
https://github.com/seratch/scaruby
Last synced: about 1 month ago
JSON representation
Scala API in Ruby
- Host: GitHub
- URL: https://github.com/seratch/scaruby
- Owner: seratch
- License: mit
- Created: 2012-02-29T08:43:15.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-02T01:30:47.000Z (over 10 years ago)
- Last Synced: 2024-04-23T22:19:38.014Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 191 KB
- Stars: 5
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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
```sh
bundle console
``````ruby
irb(main):008:0> require 'scaruby'
=> falseirb(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
=> trueirb(main):012:0> Seq.new([1,2,3]).filter {|e| e < 2 }
=> #
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 }
=> 6irb(main):025:0> Map.new({123=>'abc',23=>'bc',345=>'cde'}).filter {|k,v| k.to_s.size == 3 }
=> #"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.
```ruby
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.
```ruby
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](https://secure.travis-ci.org/seratch/scaruby.png)](http://travis-ci.org/seratch/scaruby)
## License
MIT License
https://github.com/seratch/scaruby/blob/master/LICENSE.txt