Skip to content

Instantly share code, notes, and snippets.

tl;dr: Ruby Arrays,

Objectives:MVC & Testing , Arrays & Functions ,Networking & HTTP

Ruby "Strings" vs. [Arrays]

    array: an Object with ordered storage container
```Ruby names = ["Travis", "Megan", "Tod", "Bryan"] #literal array- what you see is what you get, also json (JS object notation)

#Homework for June 18, 2013

##Calculator 1 Create a command line calculator. It should have a basic and advanced mode.

basic calculator (+, -, *, /) advanced calculator (exponents, square root)

For a basic calculator, press 1.

#Homework for June 18, 2013

##Calculator 1 Create a command line calculator. It should have a basic and advanced mode.

basic calculator (+, -, *, /) advanced calculator (exponents, square root)

For a basic calculator, press 1.

The first thing that really surprised me today was the flexibility of Ruby's shovel operator, <<. A student in the class had tried the following:

a = [0]
a << a

What do you think a is now? I was sure it would be [0, [0]]. But lo and behold, Ruby sparkles;

a = [0]
a &lt;&lt; a

General

  • method_name() to run a method with no parameters
  • .split splits a string into an array based on spaces
    • .split() splits a string into an array with the value inside the parens
    • "\n" is class block
  • Make sure the remember that an array starts with 0, and so the top number needs to be subtracted by 1
Task Code
Change the background color of '#target' by script. $('#target').css('background', 'blue');
Change the text in the span, a child of '#target' $('#target span').text('foo:bar');
Create a clone of the span in '#target' and position it under the orgin. $('#target span').clone().insertAfter('#target span');
Change background color of the second of three '.target'. $('.target').eq(1).css('background', 'blue');
Disable the button $('.target button').attr('disabled', 'disabled');
Uncheck the boxes $('.target input').removeAttr('checked');
Move '#child' from '#parent1' to '#parent2' $('#child').appendTo('#parent2');
Make the textbox in '#target' read-only $('#target input').attr('readonly', 'readonly')

How to start

  • deconstruct a program and turn it into steps-comment out in the editor
  • start with the most simple step
  • test small things in the console to reaffirm basic assumptions (do my expectations meet my results?)
  • DIVIDE AND CONQUER

##jQuery

  • div divides blocks
  • span divides in-line text
  • grabs something on the page and can see the value