Implementation for already available classes in Ruby - ruby

I am a Java Developer and a newbie in Ruby.
Does Ruby not implement available classes in Ruby lang itself(as done in Java).
Actually I have downloaded the code for Ruby and was trying to find the implementation for classes like Fixnum, etc. But could not find it.

In YARV/MRI most of the core classes are implemented in C (see array.c, bignum.c, string.c and so on) but some of the less-core classes are implemented in Ruby (e.g Set, Vector and so on).
However, in Rubinius (another Ruby implementation) almost all (afaik) of the core classes are implemented in pure Ruby.

Related

Why SortedSet was removed from stdlib in Ruby 3.0?

That was a very surprising finding when I switched my app to Ruby3+ version.
Even though it is a major version upgrade but still..
Removal of Core data type from stdlib that's been there for at least 10 years(since 1.9.3?) looks weird.
Was there any compelling reason I'm not aware of?
The error that it raises:
"The SortedSet class has been extracted from the set library. You must use the sorted_set gem or other alternatives."
After a bit of searching I found the following:
Remove SortedSet implementations PR
It required RBTree to perform decently and the external dependency was not suitable for a standard library. The pure ruby fallback implementation was originally meant to be a demonstration of how to write a subclass of Set, and its poor performance was not suitable for use in production.
I decided it should be distributed as an external library instead of bundling it with Set.
To keep it short:
SortedSet has been removed for dependency and performance reasons.
source

TCPServer Class NameError in RubyMotion (OSX)

I have some code I am porting over to RubyMotion from MacRuby and I'm getting a TCPServer Name error: Here is the error message:
app_delegate.rb:29:in `control_server:': uninitialized constant AppDelegate::TCPServer (NameError)
This is the line of code that causes the problem:
dts = TCPServer.new(ip, port)
I have read that some classes from Ruby aren't included in RubyMotion but I'm not sure which classes and how to determine which classes aren't available.
Thanks
RubyMotion doesn't include the entire Ruby standard library because RubyMotion doesn't come with a built-in way to deal with certain parts of the Ruby language that are required by lots of the standard library and community gems - such as require, eval, load and so on.
Traditionally, we've dealt with this by using Objective-C libraries instead, since RubyMotion bridges Objective-C classes seamlessly. There's a wealth of existing Objective-C libraries out there and a fabulous dependency management system in CocoaPods. If you're down for a little rewriting, the CocoaAsyncSocket library should suit your needs.
If you're feeling a little more adventurous, you could try getting your existing code working by using MotionBundler. It attempts to add require support to RubyMotion, with varying levels of success. In theory, you'd simply put back that require 'socket' line in your code after you've set up MotionBundler and it should take care of the rest. I got some pretty scary-looking stack traces when I tried it myself though, so it's probably not a silver bullet. TCPServer is particularly worrying since I'm fairly sure it uses native C extensions, which are not supported by MotionBundler.

How can I build a Ruby interpreter with only needed libraries?

How can I build a Ruby interpreter with only Core API (exclude Process class) and without standard library?
It should not include irb or anything else. A pure interpreter with necessary components.
i have no idea how you can build it, but matz (the creator of ruby) published a project that provides a minimal version of ruby called mruby: https://github.com/mruby/mruby/

How to generate bytecode in Ruby 1.9?

How can I generate byetcode from Ruby 1.9??
My intent is to generate bytecode not the source code and ship it along with my application package. I am aware of the JRuby approach but I am facing certain issues there
Call BCEL library from JRuby. BCEL library is shipped with JDK.

Ruby wrapper over a existing C library

I want write a ruby wrapper for a existing C library (.so files). Can anyone point me to books/websites that can get me started with this.
You have several options:
swig / hand written C
extension but those won't be
usable in other VM than MRI (won't
work in jruby, rubinius...)
FFI which will be usable on
other VM. example here
Take a look at FFI gem.

Resources