Question

I am new to Ruby, and new to programming. I've learned the basics of Ruby and HTML, but as I'm getting closer to beginning to work on a project, I'm having difficulty understanding how the Ruby code we write interacts with Ruby gems, vcs (specifically Git), applications like gembundler, and the HTML we write, to build a functional website. I searched for a broad overview of this process, but had no luck. Anyone have some good analogies, models, or explanations? Much appreciated!

Was it helpful?

Solution

Indeed, Ruby is but one part in the technological stack involved in web development. Here's my world view.

Gems are packages of Ruby code. They may contain libraries, utilities and applications. When you require 'x', we say that you depend on the x library. For that require call to work, you must have the x gem installed.

The process of ensuring the correct versions of all the gems your code depends on are installed is called dependecy management. Bundler is a Ruby application, packaged as a gem itself, which makes that process a lot easier. It allows you to track all your dependencies through the Gemfile or even import the dependencies declared in a gem specification. Bundler is incredibly useful for gem development. It allows you to:

  • Ensure everyone will use the same versions of gems you are using
  • Upgrade dependencies in a controlled manner
  • Painlessly execute and test your code without installing it locally as a gem

Version control systems are separate applications which track the changes made to your code, who made them and when they were made. Changes to your code may include but certainly not limited to: lines added, lines deleted, characters changed, files added, files deleted, permissions changed. A commit is a unit of change. Branches are snapshots of the project which are evolving separately and have separate changesets. Merging is the act of integrating all the changes made in two different branches and resolving any conflicts that arise.

Version control systems can be centralized or distributed. The latter is analogous to working locally on your file system. It's pretty intuitive. The difference is that you commit changes and, when you are done, push them to some central server. I've never used a centralized version control system, so I won't say anything about it.

Generally speaking from the perspective of web development, Ruby code will run on a Ruby virtual machine, accepting requests from various sources and serving data. These requests contain the information necessary to determine the response returned by the server. Information such as the kind of resource you are trying to access, data which can be used to identify that resource and the format you want your data in.

The code will then interact with a database in order to fetch the information requested, and the information will be formatted as specified. If a browser asks for a user's profile as a HTML page, Ruby will generate one, putting the requested user profile information within the correct tags. A mobile client might receive the same information encoded in json.

Ruby code will likely be supported by many dependencies, developed with the aid of Bundler and tracked by version control systems. It will probably run on virtual machines accepting requests and serving information formatted in a variety of ways.

OTHER TIPS

If I understand you question correctly, you want to know how gems are working for example how gem is extending your class methods etc.

If it is true I can recommend you a book "Metaprogramming in ruby" http://pragprog.com/book/ppmetr/metaprogramming-ruby

A lot of useful information with real life examples

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top