Dev box
I'm a 32-year-old Ruby on Rails web developer. With the help of friends and co-workers, I've been teaching myself Rails. I worked as a Rails developer for Crowd911 in Colorado. I live in Berlin.
In my developer blog I publish a stochastic array of thoughts and ideas, lessons, mistakes, questions and attempts as answers about Rails and Ruby. I am also posting Anki cards that I used to help myself study. In my view most knowledge is about practice. If you have thoughts, questions, ideas, corrections, arguments, feel free to email me at henryvw@gmail.com.

Ruby Inspect method - .inspect

Ruby Inspect Method (.inspect) or p

Inspect is a way of looking into an object and seeing everything that’s there, like its ID, and any attributes.

p is a shortcut inspect method.  Just think of the ‚p‘ in insPect.

Read More

The Ruby initialize method

Treasure class

The Initialize Method is useful for setting an object to automatically create a few basic attributes or methods when you a create a new object. 

In the image, you can see an example of a Class WITH an Initialize Method.

Without an Initialize Method, you must create separate methods to assign the attributes on your own:

class Thing

    def set_name (aName)

       @name = aName

    end

    def get_name

        return @name 

    end

Read More

How does Rails make use of Ruby hashes?

**Rails makes extensive use of a Ruby feature to pass a hash as a parameter into a method.** 

What does this mean? 

redirect_to action: ’show’, id: product.id

Rails uses Ruby hashes to pass Controller actions, for example, 

When I click on the title of a blog post on Stoic Hacks, here’s the Ruby hash that I send via Rails: 

{“action“ => “show“, “controller“ => “posts“, “id“ => “10“}

 

So part of the architecture of Rails is to use Ruby Hashes to pass instructions back and forth between the server.  

Read More

Regular Expressions and Patterns

A Regular Expression or Pattern matches custom rules applied to strings to tell you if it contains all of those things.  It is an expression used to specify a set of strings required for a particular purpose.  A Regular Expression lets you specify a pattern of characters to be matched in a string.  A simple way to specify a set of strings is simply to list its elements or members.

For example:

Handel

Händel

Haendel

could be specificed by pattern H(ä|ae?)ndel; we say that this pattern matches each of the three strings. 

gray | grey

or 

gr(a|e)y

These are equivalent patterns.

In Ruby, you typically create a regular expression by writing /pattern/ or %{pattern}.  

if line =~ /H(alä)ndel/

puts „No matter how you spell Handel, you’ve gotta love him!“

 

end

Read More

Simplest possible imaginary Ruby program

Here’s a simple Ruby program.

 

Class

def method1

end

 

 

def method2

end

end

 

variable = Class.new

variable.method1

variable.method2

Read More






Footerfull