# Ruby without framework

**URL:** <https://www.ruby-forum.com/t/ruby-without-framework/194598>\
**Category:** Ruby\
**Created:** [September 7, 2010, 6:06pm UTC](https://www.ruby-forum.com/t/ruby-without-framework/194598 "2010-09-07T18:06:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrashi12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@mrashi12](https://www.ruby-forum.com/u/mrashi12)\
**Post date:** [September 7, 2010, 6:06pm UTC](https://www.ruby-forum.com/t/ruby-without-framework/194598/1 "2010-09-07T18:06:15Z")

</div>

Can I use ruby code running in web browser without any frameworks used?  
Also anyone please tell me how to make framework, Please give me some  
tips  
or spark to start with.  
I need to make a new framework because I need to re-use the ruby code  
(actually shares the code) for desktop version and the new framework.

Is that possible?

---

<div class="post-metadata">

**Author:** ![mrashi12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@mrashi12](https://www.ruby-forum.com/u/mrashi12)\
**Post date:** [September 7, 2010, 6:37pm UTC](https://www.ruby-forum.com/t/ruby-without-framework/194598/2 "2010-09-07T18:37:52Z")

</div>

## Hi Rashad, For start you may use tiny frameworks, which you can use to study to create framework. Sinatra, Camping, Rack etc are the examples.

## Thanks and Regards Saurabh P. +91-9922071155 skype: sorab\_pune yahoo & gtalk: saurabh.purnaye msn: removed\_email\_address@domain.invalid

please don’t print this e-mail unless you really need to.

On Tue, Sep 7, 2010 at 9:31 PM, Mohammed R.

---

<div class="post-metadata">

**Author:** ![mrashi12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@mrashi12](https://www.ruby-forum.com/u/mrashi12)\
**Post date:** [September 7, 2010, 6:49pm UTC](https://www.ruby-forum.com/t/ruby-without-framework/194598/3 "2010-09-07T18:49:35Z")

</div>

On Tue, Sep 7, 2010 at 9:31 PM, Mohammed R.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can I use ruby code running in web browser without any frameworks used?  
> Also anyone please tell me how to make framework, Please give me some tips  
> or spark to start with.  
> I need to make a new framework because I need to re-use the ruby code  
> (actually shares the code) for desktop version and the new framework.

Check out rack [[http://rack.rubyforge.org/](http://rack.rubyforge.org/)] - it’s not a framework so  
much as an interface that lets your app communicate with a webserver.

Also, what I’ve done in the past when I needed to share ruby code  
between a desktop and web ui is to put most of it in libraries, and  
have a small sinatra app that used those libraries.

martin

---

<div class="post-metadata">

**Author:** ![mrashi12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@mrashi12](https://www.ruby-forum.com/u/mrashi12)\
**Post date:** [September 7, 2010, 7:46pm UTC](https://www.ruby-forum.com/t/ruby-without-framework/194598/4 "2010-09-07T19:46:05Z")

</div>

Mohammed R. wrote:

> Can I use ruby code running in web browser without any frameworks used?

The key thing to think about is, how does an incoming HTTP request end  
up being processed by your ruby code? There are several options.

(1) Probably the most common option is to run a webserver written _in_  
ruby (e.g. webrick), or in a combination of ruby and C (e.g. mongrel,  
thin, unicorn). They will make a call to your code when the request  
comes in.

Your app runs as a separate process, and listens on its own TCP socket.  
So your URL might be something like [http://x.x.x.x:4567/](http://x.x.x.x:4567/)

If desired, you can proxy to this from another webserver in front.

(2) You can run Apache or Nginx with Phusion Passenger, a.k.a.  
mod\_rails. This integrates into the webserver, starting ruby processes  
as necessary and passing HTTP requests to them using the Rack API.

(3) Your webserver can run your ruby script as a CGI, which means it  
starts a new process running your script for each incoming request,  
passing the request on STDIN and the headers in environment variables,  
and getting the response on STDOUT. This is inefficient because it  
involves starting a whole new ruby interpreter for each request. It  
becomes extremely inefficient if your ruby code in turn loads lots of  
other ruby libraries.

(4) There are some other options like FastCGI and SCGI, rarely used now.

Fortunately, all these options support mapping HTTP requests to the same  
API: Rack. If you write your code using Rack, or any other framework  
which sits on top of Rack (including Rails, Sinatra, Camping), then you  
can run the same code under any of the above scenarios, just by changing  
a config file.

> Also anyone please tell me how to make framework, Please give me some  
> tips  
> or spark to start with.  
> I need to make a new framework because I need to re-use the ruby code  
> (actually shares the code) for desktop version and the new framework.

That depends on what you mean by “framework”. Normally “framework” means  
code someone has already written, that you plug your customisations  
into. You don’t write a new framework from scratch, you just pick one  
and extend it.

For code which is shared between a desktop app and a web app: just put  
it in a library (lib/foo.rb) which can be used by either.

To be honest, if you write a good web app, you won’t need a desktop one,  
and it will save you a lot of pain installing graphic libraries and  
frameworks. Everyone has a browser; just point it at localhost. This is  
where the web server written _in_ ruby comes into its own.
