Coder Social home page Coder Social logo

ruby_primer's Introduction

The Ruby Primer

© Copyright 2011 C42 Engineering. All Rights Reserved.

Teach Ruby!

Fork this repository, make changes and use the RubyMonk Sandbox for a live preview. Send us a pull request when you are done!

The Ruby Primer is an open collaboration initiative that uses the [RubyMonk][] platform to help teach the Ruby Programming Language.

How to Contribute

  • Fork this repository.
  • run bundle install && bin/rubymonk.rb to generate the URL to your very own RubyMonk sandbox.
  • Use the generated URL to preview the contents in the sandbox.
  • Make your changes in docs/. The sandbox URL will get updated with your changes as you make them.
  • Once you are happy with your changes, send us a pull request with a clear description of changes you've done.
  • Like any other open-source project, your pull request will be reviewed and then merged.

How does this work?

The RubyMonk platform allows you to create and publish online e-books that contain embeddable, runnable Ruby code and tests.

RubyMonk uses standard Haml markup in combination with our very own DSL to achieve this. When you fork this repository and send us a pull request you are contributing content to The Ruby Primer, an introductory primer to the Ruby language.

The Ruby Primer is a free, open and interactive e-book published on the RubyMonk platform.

The Magic DSL

All the content is inside docs/. The lessons are placed inside docs/<chapter>/<lesson_name>.

The lessons make use of standard Haml markup for content. It is interspersed with metadata that allows you to define code blocks.

Every lesson starts with a section. A section needs a short_name and a title.

Here is a template:

title - <Title of the lesson>
.section :a_short_name_of_the_section, "Title of the section"
  %p
     A paragraph. You can use any valid Haml here. Be mindful of the spacing though!

  !enchant
    short_name :short_name_of_the_exercise
    exercise!
    starting_code <<-DATA
      # sample starting code.
      # uses Ruby's multiline construct.
      # code that will appear in the block by default.
    DATA
    code_wrapper <<-DATA
      # you can use ERB templating here.
      # the user_code is passed as a variable to the templating engine.
      def method_that_gives_result_of_the_users_input
        <%= user_code %>
      end
    DATA
    specs <<-DATA
      #
      it "the user should give the string xyz to pass this spec" do
        method_that_gives_result_of_the_users_input.should eq('xyz')
      end
    DATA
  !release

The !enchant starts a block of exercise. Use !release once you are done. Every !enchant block mandatorily requires the following attributes:

  • exercise! or example! : An exercise has specs which have to pass for the user to continue. An example can be run, but does not affect the user's progress.
  • short_name : short_name is used in the URLs for referring to the section.
  • starting_code : Sample code that will appear by default in the code-block.
  • code_wrapper : This is the block of code where you create a method to wrap the code written by the user. RubyMonk uses ERB templating to render it, the user's code is passed in as the variable user_code.
  • specs : RSpec block that tests the method in the code_wrapper.

An exercise needs to have:

  • starting_code
  • code_wrapper
  • specs

An example needs to have:

  • starting_code

The numbers in the section and enchant lines are the ids of the metadata. You can skip adding a number there if you are creating a new section. But when modifiying existing section/enchant blocks that have an id, please leave them as is.

Go ahead and check out the existing lessons to get a hold of the DSL better.

Scope

The Ruby Primer is targeted at programmers who are learning Ruby for the first time. However people who are completely new to programming have also found it useful. The scope of The Ruby Primer is to cover just enough basics to help one get started with Ruby.

Prerequisites

  • Ruby - CRuby 1.9.2 and upwards are supported.
  • Bundler (gem)

The Ruby Primer sandbox client has been tested on Linux and Mac OS X. We welcome help in ensuring compatibility with Windows.

Got any questions? Talk to us!

ruby_primer's People

Contributors

aakashd avatar jasim avatar kitallis avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.