background preloader

Ruby Tutorial with Code Samples

Ruby Tutorial with Code Samples

Related:  RubysunnyshivaRuby

Dependency injection != Inversion of Control David Heinemeier Hansson, the creator of Rails, recently posted his thoughts on dependency injection. The post is written in an unhelpful inflammatory style, and it’s inaccurate in its use of the terms involved. In particular, there is a confusing conflation of the ideas of dependency injection, a simple programming pattern I use every day, and Inversion of Control (IoC) containers, which are sometimes called “Dependency Injection containers”. These are a heavyweight implementation of dependency injection wrapped around the whole application.

How to Wire Up Ruby on Rails and AngularJS as a Single-Page Application (Gulp Version) - Angular on Rails Why this tutorial exists I wrote this tutorial because I had a pretty tough time getting Rails and Angular to talk to each other as an SPA. The best resource I could find out there was Ari Lerner’s Riding Rails with AngularJS. Destructuring assignment in Ruby My post on underscores in Ruby attracted quite a lot of interest, particularly on the topic of destructuring assignment, so I thought I’d go into a bit more detail. As mentioned previously, Ruby supports destructuring assignment. You can assign an array to multiple variables both in direct assignment: a, b, c = [1, 2, 3] and in block parameters:

Constraint programming in Python By : Shabda Raaj Imagine this, you want to solve a problem, the algorithm for which you do not know. You just know the problem. From wikipedia,Constraints differ from the common primitives of imperative programming languages in that they do not specify a step or sequence of steps to execute, but rather the properties of a solution to be found. How to Wire Up Ruby on Rails and AngularJS as a Single-Page Application - Angular on Rails This post is now somewhat outdated. If you’re interested in Angular/Rails/Grunt/JavaScript/HTML, read on. If you’d prefer Angular/Rails/Gulp/CoffeeScript/Jade, check out this newer post. Why this tutorial exists I wrote this tutorial because I had a pretty tough time getting Rails and Angular to talk to each other as an SPA.

Ruby Programming/Syntax/Control Structures Control Structures[edit] Conditional Branches[edit] Ruby can control the execution of code using Conditional branches. Recursive Descent Parser for Ruby Sometimes strange things happen. I've been developing a small, basic recursive descent parser for Ruby called RDParse. Just before writing this post I decided to Google that name, and lo and behold the first result is a Ruby recursive descent parser called RDParse, created by Dennis Ranke, that I posted to Code Snippets for posterity several months ago. Since both of these libraries are unlikely to be used at once and that Dennis doesn't seem to be maintaining his version, I've decided to stick with RDParse as the name of mine for now. You can download my RDParse as rdparse.rb.txt, just rename it at your end if you want to use it.

AngularJS Tutorial: Learn to Build Modern Web Apps with Angular and Rails The goal of this tutorial is to guide you through the creation of a Reddit/Hacker News clone using Rails 4 and AngularJS. By completing this tutorial, you will gain a basic understanding of Rails and AngularJS, using Rails to build a JSON REST API that interacts with an AngularJS frontend. Prerequisites This course assumes knowledge of programming and at least basic knowledge of JavaScript and Ruby, and you should be comfortable with basic web application concepts including REST and CRUD. Before you begin, you will also need to have Node.js and Rails already installed. Ruby If Examples: Elsif, Else and Unless Keyword Array Hash String 2D Case Class Console Convert DateTime Exception File Format If Iterator Math Method Nil Number Regexp Replace Set Sort Split Substring While In a program, statements are sequentially executed. One comes after another. With an if-statement, we introduce a branch.

Ruby Version Manager - Installing RVM ∞Quick (guided) Install Before any other step install mpapis public key (might need gpg2) (see security) gpg --keyserver --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 **Note: can sometimes timeout you may want to use different keyserver -