Self or not, living in Ruby life

In Ruby, when we say ruby.upcase is telling the object ruby to do the message upcase( the method name ). However, when we say the method puts, Ruby already have the investable object “SELF” which we do not need to put in front of the method puts. So what is “SELF”? Self in Ruby is the default receiver for method calls which always reference the “current object”, and it change depending on where you are. When we puts self in Ruby, it will show the local object reference by self as main, and when we puts self.class into Ruby, it shown self’s Ruby class is an object. So in this case, self is the goest since we do not need to type self into Ruby.

Some people might ask if we ever need self in Ruby then. The answer is yes.

class Software

   def self.print_developer

       puts “The developer of this software is Jason”

   end

end

Software.print_developer

In the context of a class, even self still refers to the current class in this case, which simply become an instance of the class Class now. Defining a method on self creates a class method. *self = Software

Rspec for OmniAuth

ryanspittler's avatarRyan Spittler

Working on a group project as part of the Building the Toolbelt of a Junior Ruby on Rails course that I am taking, I implemented the use of OmniAuth. I followed the example that we had learned in class. We have been using Rspec for our TDD, however, we had not learned the specific tests to write for OmniAuth. How hard could those be?

View original post 883 more words

Ambiguous match RSPEC ERROR

Working on my personal project this weekend, and feeling a little more comfortable with my coding.

However, tonight I found the new RSPEC error I had never seen before.

Failures:

 1) Managing user New user can sign up

    Failure/Error: click_link ‘Signup’

    Capybara::Ambiguous:

      Ambiguous match, found 2 elements matching link “Signup”

On my personal project Study Tool’s home page, I have 2 “Signup” links and the RSPEC don’t know which link to click on. My 1st solution is search online, which I tried first(‘.signup a’).click_link ‘Signup’

which raise another error

Failures:

1) Managing user New user can sign up
Failure/Error: click_links ‘Signup’
NoMethodError:
undefined method `click_links’ for #<RSpec::ExampleGroups::ManagingUser:0x007fe868898c28>

Then I saw Anthony was on Slack by the time and start chat with him about this errors.

First, he suggest me to save_and_open_page and see if you see multiple links on the page. Even I already know I have two links of ‘Signup’, I still use the save_and_open_page to see this on the page.Screen Shot 2015-04-25 at 10.02.34 PM

Anthony also suggest me first(:link, link).click   in RSPEC, so I change it into first(:link, link).click_link ‘Signup’ , and it raise another error

Failures:

 1) Managing user New user can sign up

    Failure/Error: first(:link).click_link ‘Signup’

    Capybara::ElementNotFound:

      Unable to find link “Signup”

We tried to change the line into first(:Signup, Signup).click, and it raise another error

Failures:

 1) Managing user New user can sign up

    Failure/Error: first(:Signup, Signup).click_link ‘Signup’

    NameError:

      uninitialized constant Signup

Then we check on the Inspect Element on this two ‘Signup’ link Screen Shot 2015-04-25 at 10.05.31 PM Screen Shot 2015-04-25 at 10.07.14 PM, and change the line as   second(:link, ‘Signup’).click  this time. However, it still raise another error

Failures:

 1) Managing user New user can sign up

    Failure/Error: second(:link, ‘Signup’).click_link ‘Signup’

    NoMethodError:

      undefined method `second’ for #<RSpec::ExampleGroups::ManagingUser:0x007fb3ff4fe718>

I don’t want to change my app for the spec since is a really good way for me to learn RSPEC. I did some research on Capybara, and read this blog http://techblog.fundinggates.com/blog/2012/08/capybara-2-0-upgrade-guide/ , and I’m start thinking, what if I point it to the link first, than tell it to click the link? so I try

first(:link, 'Signup').click
click_link 'Signup'

Yeah! success I finally got this error fixed! Now I can have a nice sleep ;D

Rails magic!

Rails is a skeleton web-application framework, it base on Model-View-Controller (MVC) pattern includes everything that needed to create database-backed web applications.

To create a new rails app type the following in the terminal: rails new <apps-name> -T -B, the -T is skip Testing, -B is skip Bundle since we might need to adding some more gem later.

rails g/generate, it generate new basic code for us into all different files.

rails c/console, it start the rails console. Rails console is basically IRB in Ruby, but rails c is for Rails.

rails s/server, it start the rails server. Which give us access to localhost:3000 in the browser of the web we just create.

There were 3 main directories under app directory we will be focus on, which are controllers, models, views. Yes, this are the MVC pattern.

Gemfile is also really important part of this app. It tell the rails app what gems that we depends on in order to run. We’ll need the rails gem to run rails, then we also need sqlite3 gem to cornet to sqlite database, and all other gems that we needs depend on our app. After we finish adding all the gems that we need, we will need to run bundle or bundle install to install all the apps.

Development, Production, and Testing area

As a beginner developer in ruby on rails. We learned how the webs work with MVC, CRUD, linking the Web into Apps (Rails in this case) which including User, Browser, Router, Controller, Model, View, Data Base. I’ll talk about CRUD in my future blogs in Rails. Today I want to focus on the three different stage: Development, Production, and Testing.

Development, which is the local area when wrote our code, some time it will be internal website for people who authorize to CRUD. Normally we use ‘rails s’ or ‘rails service’ in our terminal/I-term to pull up the service, than type in ‘localhost:3000’

Testing area is complete different stage area for test purpose to test if the web will be function or not. If you use Rspec TDD, it would even lead you of how to code your web as well. Professor Jason Noble’s favor quote of TDD is ‘RED, GREEN, REFACTOR’ (Red means write a fail test, Green means make the test pass, Refactor means make the code more professional such as take care of DRY codes).

Production, usually is the finished life website for the clients.

Please let me know if you have any thoughts of this stage areas.

Thoughts of reading Finding Your Inner Programmer: Part 1 by Jeff Casimir

Our Professor Jason Noble gave us a blog link Finding Your Inner Programmer: Part 1 by Jeff Casimir to read. Professor also asked us to write a blog of what we think of this.

Jeff Casimir talked about the LSAT (Law School Admission Test) is required for admission to most law schools and is offered four times each year. I feel this depends on how we are using the TEST. Of course if the test is just sort out students different level, and put those students who have the same level as a group to study would be really helpful. However, if this required test going to take away of those who don’t have any knowledge but really want to try and open a door for new career, I would not agree with this action. I understand this world there is nothing fair, but at least, we should all have a chance, a key, maybe a little guide to help us to see the light.

“There are many people, programs, and instructional tools that will tell you anyone can program.” That’s true. Now a day, there are a lot of people out there in the programing field that study on their own with some books, online programs and jump on working, earning experience. However, how many of them have enough foundation to understand how their code works? When the bugs kick in, what really happens and how to fix it?Grumpy-Cat-Patching-Bugs-Developer-Meme I agree of Jeff’s “That’s true in the same sense that just about anyone can write a book, but not all of us should be authors. The art of crafting characters, a dramatic arc, and life-like dialog is the work of those with an aptitude for storytelling combined with long hours of practice.” A true story, one of my friend who in the field for a while, but some times I can impress him with some basic skills that I have learned in class. When he shown me the company code, I almost cry~ most of them make no scene to me and he cannot even fully explained to me what is that code doing. gram codingHe told me that he use a lot of online reference to put all the code together, but one big issue is that it is not fully his own coding style, so many bugs that just take hours, days, weeks, even years to fix…more over, is just temporary fix. It can be break down again after 2 hours, or 3 month later. Such as a writing a book, you can put 10 different people’s story together as a story. However, can I ask what is your soul, your spirit, your purpose of this story? I believe that an authors have their own purpose on each book they wrote with their soul, and spirit support. I think same as programmer, we need to have our patience to understanding what we are doing. Write a program is kind of raise a child. We need to step by step, lead them to what needs to be done by break them down into little piece by piece. Put them together logically.

“Anyone can write a program, but not everyone can be a programmer. A programmer is a person who uses software to solve problems.” This part I don’t really agree. Is it really anyone can write a program? kitty coding

Do you mean anyone can write a functioning program? Each person on earth have their special unit skills for sure, but I believe some people are just won’t able to write a program that would function. Such as some people cannot do match, some people cannot draw etc. However, I do believe “a programmer is a person who uses software to solve problems.” because making software to solve problems is the purpose for programming language exist, at least this is how I believe. What do you think?

I believe I can be what I want to be, I believe I can be a programmer. Just depends on how I find the way to build up my foundation, how I walk my path into this field, and find the best way to study more, practice more. For me, believe is a magic, is a power to lead me forward. You never know if that 90% of brain usage will open your path with magic until you try and try hard, right? We won’t have light balls today if Thomas Edison don’t believe in himself. Thomas Edison said that “Genius is one per cent inspiration and ninety-nine per cent perspiration. Accordingly, a  ‘genius’ is often merely a talented person who has done all of his or her homework.” And I believe a good programmer just need to study hard, practice more, and believe in yourself. Please and you are welcome to share your thoughts.

Run!!!! It’s a cop. Oh, don’t worry! If you fix it, Rubocop will stop screaming at you ;)

Rubocop refers to each common code smell and check as a cop, is a Ruby static code analyzer.

I have a nightmare last night that I get “cop” when I try to run away, and she (Rubocop) said “STOP! Either you fix the code, or I will kill you.” robo_cop_cosplay

So, here I am to find a cop, and see what it looks for in my Ruby code. So let’s take a look at variable.rb

I’m going into my self_practice directory, making a new directory call rubocop_variable_testing. Inside of rubocop_variable_testing directory, setup RVM load Ruby 2.1.5 and the davinci_t1_2015 gemset.

Screen Shot 2015-02-19 at 6.54.55 PM

Then I need to add the guard-rubocop gem.

source 'https://rubygems.org&#39;
gem 'guard-rubocop'
gem 'guard-rspec'
view raw Gemfile hosted with ❤ by GitHub

Since in class T1 2015 we didn’t cover rspec yet, we can comment out line 4 for now. Let’s bundle them in the iTerm, and initialize guard. Screen Shot 2015-02-19 at 7.15.09 PM

In RubyMine should have a jump up on the left by now. How do we not getting screaming by itself while fire up guard? Screen Shot 2015-02-19 at 7.28.08 PM

The answer is go into RubyMine, highlight the directory robocop_variable_testing, command + N, create a new file call <.rubocop.yml>, and put into the following code.

AllCops:
Exclude:
- 'Guardfile'
view raw .rubocop.yml hosted with ❤ by GitHub
Now rubocop should be happy for a little while. Screen Shot 2015-02-19 at 7.31.06 PM

Let’s create a ruby file call <variable_force.rb>, and start

#!/usr/bin/env ruby
professor = 'jason'
lesson = 'Building the Toolbell of a Junior Ruby on Rail Developer'
school = 'DaVinci'
quote1 = "Don't be a jerk"
quote2 = "Google never forget!"
 Screen Shot 2015-02-19 at 8.01.23 PM

Since I’m not allow to run away, I’m just going to fix them. Shall we? robo_cop_cosplay“Fix or Die!” (Totally joking)

First, let’s fix the Useless assignment to variable offenses from line 1 to line 5 with one extra line 😉  Ready?

#!/usr/bin/env ruby
professor = 'jason'
lesson = 'Building the Toolbell of a Junior Ruby on Rail Developer'
school = 'DaVinci'
quote1 = "Don't be a jerk"
quote2 = "Google never forget!"
puts "#{school} #{professor.capitalize} in #{lesson} said:'#{quote1} because #{quote2}' "
However, now I have a new offense variable_force.rb:9:81: C: Line is too long. [89/80] puts “#{school} #{professor.capitalize} in #{lesson} said:’#{quote1} because #{quote2}’ ” Screen Shot 2015-02-19 at 8.14.47 PM

Well, let’s fix this by break down this long line.

#!/usr/bin/env ruby
professor = 'jason'
lesson = 'Building the Toolbell of a Junior Ruby on Rail Developer'
school = 'DaVinci'
quote1 = "Don't be a jerk"
quote2 = "Google never forget!"
puts "#{school} #{professor.capitalize} in #{lesson}
said:'#{quote1} because #{quote2}' "

Another common offense in rubocop look like this: Inconsistent indentation detected. quote2 = “Google never forget!”, and we can fix by delete extra useless indentation shown in the following line 7.

#!/usr/bin/env ruby
professor = 'jason'
lesson = 'Building the Toolbell of a Junior Ruby on Rail Developer'
school = 'DaVinci'
quote1 = "Don't be a jerk"
quote2 = "Google never forget!"
puts "#{school} #{professor.capitalize} in #{lesson}
said:'#{quote1} because #{quote2}' "

The super popular offense that rubocop love to scream at are Prefer single-quoted strings when you don’t need string interpolation or special symbols. quote2 = “Google never forget!”, and we can simply fix it by change it out to single quote such as the following.

#!/usr/bin/env ruby
professor = 'jason'
lesson = 'Building the Toolbell of a Junior Ruby on Rail Developer'
school = 'DaVinci'
quote1 = "Don't be a jerk"
quote2 = 'Google never forget!'
puts "#{school} #{professor.capitalize} in #{lesson}
said:'#{quote1} because #{quote2}' "
Or else, you can disable the double-single quote in rubocop.

Finally, the last common offense I’m covering tonight is 1 trailing blank lines, which we just delete the extra blank line we don’t use at the end. 

#!/usr/bin/env ruby
professor = 'jason'
lesson = 'Building the Toolbell of a Junior Ruby on Rail Developer'
school = 'DaVinci'
quote1 = "Don't be a jerk"
quote2 = 'Google never forget!'
puts "#{school} #{professor.capitalize} in #{lesson}
said:'#{quote1} because #{quote2}' "

Guess what? Screen Shot 2015-02-19 at 9.30.15 PMRubocop

Haha…I guess tonight I won’t have nightmare from rubocop. Just joking. Hope you like it 😉

GIT101 practice for fun :P

Let’s play with git practice step by step, shall we?

Here we go:

change into self_practice directory for class T1-2015

cd ~/workspace/davinci_coders_t1_2015/self_practice

make a new directory call practice

mkdir practice

get into the practice directory

cd practice/

In the practice directory, make a git_warmup directory

mkdir git_warmup

get into the git_warmup directory

cd git_warmup/

In the git_warmup directory:

Setup RVM

echo ‘2.1.5’ > .ruby-version

echo ‘git_warmup’ > .ruby-gemset

Get RVM to reload these setting:

cd .

rvm current

Setup Robocop

mine .

Screen Shot 2015-02-15 at 4.50.45 PM

When RubyMine is open,

Screen Shot 2015-02-15 at 4.47.22 PM

we use shortcut command + N to create a new file.

Screen Shot 2015-02-15 at 4.47.43 PM Screen Shot 2015-02-15 at 4.48.03 PM

Type in <Gemfile> and click [OK] button. Screen Shot 2015-02-15 at 4.48.38 PM

In Gemfile, we type in source ‘http://rubygems.org&#8217; in line 1, and gem ‘guard-rubocop’ in line 3.Screen Shot 2015-02-15 at 4.50.13 PM

Now we bundle the gems into our RubyMine files. Screen Shot 2015-02-15 at 5.02.00 PM

Time to initialize guard with guard init, Screen Shot 2015-02-15 at 5.04.31 PM

and you should see in your RubyMine have a Guardfile jump up in there. Screen Shot 2015-02-15 at 5.05.09 PM

Now when your fire up guard, you will see that there are already 2 offenses for guard file alone. Screen Shot 2015-02-15 at 5.12.26 PM

To fix this, we highlight the git_warmup directory, and going to create a new file command + N with a name <.rubocop.yml> in RubyMine. Screen Shot 2015-02-15 at 5.21.51 PM

And put into these code into <.rubocop.yml> to exclude guardfile in rubocop: 

AllCops:
  Exclude:
    - 'Guardfile'

then the rubocop will tell you Screen Shot 2015-02-15 at 5.27.21 PM.

Setup Git

Command + T in iTerm to open a new tape, git init to create an empty repo locally, adding initial files, check status, commit initial setup files. Screen Shot 2015-02-15 at 5.34.50 PM 

If you hit (enter) after git commit, you are now into vim, just hit i turn into Insert mode and type in your commit message ‘Added initial setup files‘, hit [esc] button,  type :wq to save the change and quit vim

use git log -p to show any commit in this repo. Screen Shot 2015-02-15 at 5.38.57 PM

hit q to exit vim.
In the git _warmup directory:
create a ruby program call greeting
You can either go to iTerm type in touch greeting.rb, or go into RubyMine highlight git_warmup directory, command + N, and type in greeting.rb, then click [OK] button. Has the program ask for your name, then print out “Nice to meet you, (your name here).”
#!/usr/bin/env ruby
print 'What is your name?'
name = gets.chomp.capitalize
puts "Nice to meet you, #{name}."
view raw gistfile1.rb hosted with ❤ by GitHub

Now I want to check my git status. Screen Shot 2015-02-15 at 6.26.50 PM

I’m feeling a little lazy today, let’s use gitx [enter]. Now we have a gitx box jump up, and I am using shortcut command + A to selected all files from the left box that I need to commit and draft them to the right box. Screen Shot 2015-02-15 at 6.33.21 PM Screen Shot 2015-02-15 at 6.36.39 PM

put into commit message into the middle and click [commit] button, than close it on the left top [x] red button. Screen Shot 2015-02-15 at 6.38.46 PM

When we type in git log, and we now have 2 commit repository. 

Now, let’s push a new repo on github.

Let’s go to github.com/new Screen Shot 2015-02-15 at 6.45.38 PM

and we put into the Repository name as git_self_practice_for_fun_1, type in Description as just practice git101 for fun, then click [Create repository] button. Screen Shot 2015-02-15 at 6.53.51 PM Make sure the [ssh] button is check on this new page, since we already have existing repository, we click the clipboard button on the …or push an existing repository from the command line, then go paste it onto iTerm using shortcut command + V [enter]. Screen Shot 2015-02-15 at 6.57.57 PM

I’m not so sure if I get this down yet, how do I get more practice?

Let’s start the next one in the same directory practice 

Graces-MacBook-Pro:git_warmup2 RiverGracefish$ cd ..
Graces-MacBook-Pro:practice RiverGracefish$ pwd
/Users/RiverGracefish/workspace/davinci_coders_t1_2015/self_practice/practice
Graces-MacBook-Pro:practice RiverGracefish$ ls
git git_warmup
Graces-MacBook-Pro:practice RiverGracefish$ mkdir git_warmup2
Graces-MacBook-Pro:practice RiverGracefish$ cd git_warmup2
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ echo '2.1.2' > .ruby-version
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ echo 'git_warmup' > .ruby-gemset
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ cd .
ruby-2.1.2 - #gemset created /Users/RiverGracefish/.rvm/gems/ruby-2.1.2@git_warmup
ruby-2.1.2 - #generating git_warmup wrappers...............
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ mine .
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ bundle
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies...
Installing ast 2.0.0
Installing parser 2.2.0.3
Installing astrolabe 1.3.0
Installing hitimes 1.2.2
Installing timers 4.0.1
Installing celluloid 0.16.0
Installing coderay 1.1.0
Installing ffi 1.9.6
Installing formatador 0.2.5
Installing rb-fsevent 0.9.4
Installing rb-inotify 0.9.5
Installing listen 2.8.5
Installing lumberjack 1.0.9
Installing nenv 0.2.0
Installing shellany 0.0.1
Installing notiffany 0.0.5
Installing method_source 0.8.2
Installing slop 3.6.0
Installing pry 0.10.1
Installing thor 0.19.1
Installing guard 2.12.1
Installing powerpack 0.1.0
Installing rainbow 2.0.0
Installing ruby-progressbar 1.7.1
Installing rubocop 0.29.1
Installing guard-rubocop 1.2.0
Using bundler 1.6.2
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ guard init
19:19:38 - INFO - Writing new Guardfile to /Users/RiverGracefish/workspace/davinci_coders_t1_2015/self_practice/practice/git_warmup2/Guardfile
19:19:38 - INFO - rubocop guard added to Guardfile, feel free to edit it
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ guard
19:20:04 - INFO - Inspecting Ruby code style of all files
warning: parser/current is loading parser/ruby21, which recognizes
warning: 2.1.5-compliant syntax, but you are running 2.1.2.
Inspecting 2 files
.C
Offenses:
Guardfile:27:9: C: Use %r only for regular expressions matching more than 1 '/' character.
watch(%r{.+\.rb$})
^^^^^^^^^^^
Guardfile:28:9: C: Use %r only for regular expressions matching more than 1 '/' character.
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 files inspected, 2 offenses detected
19:20:05 - INFO - Guard is now watching at '/Users/RiverGracefish/workspace/davinci_coders_t1_2015/self_practice/practice/git_warmup2'
[1] guard(main)> exit
19:20:12 - INFO - Bye bye...
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ guard
19:21:35 - INFO - Inspecting Ruby code style of all files
warning: parser/current is loading parser/ruby21, which recognizes
warning: 2.1.5-compliant syntax, but you are running 2.1.2.
Inspecting 1 file
.
1 file inspected, no offenses detected
19:21:35 - INFO - Guard is now watching at '/Users/RiverGracefish/workspace/davinci_coders_t1_2015/self_practice/practice/git_warmup2'
[1] guard(main)> exit
19:21:37 - INFO - Bye bye...
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ git init
Initialized empty Git repository in /Users/RiverGracefish/workspace/davinci_coders_t1_2015/self_practice/practice/git_warmup2/.git/
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
.rubocop.yml
.ruby-gemset
.ruby-version
Gemfile
Gemfile.lock
Guardfile
nothing added to commit but untracked files present (use "git add" to track)
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ git add .ru* Gemfile* Guard*
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ git commit -m 'Added initial setup'
[master (root-commit) 828d37f] Added initial setup
6 files changed, 100 insertions(+)
create mode 100644 .rubocop.yml
create mode 100644 .ruby-gemset
create mode 100644 .ruby-version
create mode 100644 Gemfile
create mode 100644 Gemfile.lock
create mode 100644 Guardfile
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ ruby greeting.rb
What is your name? Phil
Nice to meet you, Phil.
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ ruby greeting.rb
What is your name? lovephilippe
Nice to meet you, Lovephilippe.
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ ruby greeting.rb
What is your name? smile
Nice to meet you, Smile.
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ git add greeting.rb
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ git commit -m 'adding greeting file'
[master c853877] adding greeting file
1 file changed, 6 insertions(+)
create mode 100644 greeting.rb
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ git remote add origin git@github.com:RiverGracefish/git_self_practice_for_fun_2.git
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ git push -u origin master
Counting objects: 11, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (11/11), 1.84 KiB | 0 bytes/s, done.
Total 11 (delta 1), reused 0 (delta 0)
To git@github.com:RiverGracefish/git_self_practice_for_fun_2.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ ls
Gemfile Gemfile.lock Guardfile greeting.rb
Graces-MacBook-Pro:git_warmup2 RiverGracefish$ cd ..
Graces-MacBook-Pro:practice RiverGracefish$ ls
git git_warmup git_warmup2
Graces-MacBook-Pro:practice RiverGracefish$

code for <Gemfile>

source 'https://rubygems.org&#39;
gem 'guard-rubocop'
gem 'guard-rspec'
view raw Gemfile hosted with ❤ by GitHub

code for <.rubocop.yml>

AllCops:
Exclude:
- 'Guardfile'
view raw .rubocop.yml hosted with ❤ by GitHub

Want more practice? Repeat 😉

Valentine’s Day party~ number and string for fun ;)

Valentine’s Day is coming up soon, I hope this will be a fun blog for every one!

Let’s start with Amanda’s Valentine’s Day Party

  1. Amanda is planning on having 24 kids at her Valentine’s Day party, including herself. She invited ten girls. How many boys did she invite?
  2. Amanda is going to buy cupcakes for the party. There are a dozen in each box. How many boxes will she need?
  3. Amanda’s father says that Amanda must not spend more than $1.75 per person on the party supplies. Amanda has fifty dollars. That means that she should have at least how much money left over after she buys the supplies?
  4. One third of the kids at the party will be coming from Amanda’s old neighborhood. How many kids are coming from her old neighborhood?
  5. Everyone at the party will bring a Valentine card for everyone else at the party. How many cards is that altogether?

If you are currently in Jason Noble’s class T1 2015. We’ll do the following to practice for fun, you are welcome to follow me.

First, go to terminal and type in

  cd ~/workspace/davinci_coders_t1_2015/building_the_toolbelt_t1_2015/

  mkdir self_practice

  cd self_practice

  mkdir number_and_string

  cd number_and_string

  touch amandas_valentines_party.rb

  mine .

When the RubyMine jump up, here’s how we do in the following:

# 1. Amanda is planning on having 24 kids at her Valentine’s Day party, including herself. She invited ten girls. How many boys did she invite?
# 2. Amanda is going to buy cupcakes for the party. There are a dozen in each box. How many boxes will she need?
# 3. Amanda’s father says that Amanda must not spend more than $1.75 per person on the party supplies. Amanda has fifty dollars. That means that she should have at least how much money left over after she buys the supplies?
# 4. One third of the kids at the party will be coming from Amanda’s old neighborhood. How many kids are coming from her old neighborhood?
# 5. Everyone at the party will bring a Valentine card for everyone else at the party. How many cards is that altogether?
amanda_party_total_guests = 24
number_of_girls = 10
cupcakes_per_box = 12
amandas_money = 50
supplies_cost_per_guest = 1.75
puts "There are #{amanda_party_total_guests - number_of_girls} boys Amanda invited to her Valentine's Day Party."
puts "Amanda need #{amanda_party_total_guests / cupcakes_per_box} boxes of cupcakes for the party."
puts "Amanda should have at least $#{amandas_money - (amanda_party_total_guests * supplies_cost_per_guest)} left after she buys the supplies."
puts "There are #{amanda_party_total_guests / 3} kids coming from Amanda's old neighborhood."
puts "There are total #{amanda_party_total_guests * amanda_party_total_guests} Valentine cards hanging out from this party."

Now we can run it in RubyMine by short cut “Shift + Control + R”, or go up to the menu click RUN/ RUN/ then click the file you want to run, in this case which is amandas_valentines_party.rb. You can also run it in the terminal by type in ruby amandas_valentines_party.rb

This is just the most simple way. Of cause Jason will tell you that TMTOWTDI, which stand for There’s more than one way to do it. So, let’s see what other way we can do this also. The following codes assign the formulas to new variables, which make the print line “puts” more clear.

# 1. Amanda is planning on having 24 kids at her Valentine’s Day party, including herself. She invited ten girls. How many boys did she invite?
# 2. Amanda is going to buy cupcakes for the party. There are a dozen in each box. How many boxes will she need?
# 3. Amanda’s father says that Amanda must not spend more than $1.75 per person on the party supplies. Amanda has fifty dollars. That means that she should have at least how much money left over after she buys the supplies?
# 4. One third of the kids at the party will be coming from Amanda’s old neighborhood. How many kids are coming from her old neighborhood?
# 5. Everyone at the party will bring a Valentine card for everyone else at the party. How many cards is that altogether?
amanda_party_total_guests = 24
number_of_girls = 10
cupcakes_per_box = 12
amandas_money = 50
supplies_cost_per_guest = 1.75
number_of_boys = amanda_party_total_guests - number_of_girls
total_boxes_of_cupcakes = amanda_party_total_guests / cupcakes_per_box
amandas_balance = amandas_money - (amanda_party_total_guests * supplies_cost_per_guest)
old_naighbors = amanda_party_total_guests / 3
total_cards = amanda_party_total_guests * amanda_party_total_guests
puts "There are #{number_of_boys} boys Amanda invited to her Valentine's Day Party."
puts "Amanda need #{total_boxes_of_cupcakes} boxes of cupcakes for the party."
puts "Amanda should have at least $#{amandas_balance} left after she buys the supplies."
puts "There are #{old_naighbors} kids coming from Amanda's old neighborhood."
puts "There are total #{total_cards} Valentine cards hanging out from this party."

Don’t forget to run it see if it works or not 😉

Please leave a comment let me know if it’s helpful or not, or any topic you wish me to talk about on my blog. Thanks, and have a nice day.