Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panda & tiger level assignment complete #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dramanat
Copy link

I'm not sure if I moved the about page to the homepage correctly.

get '/about' do
about_me = Array["a human being", "female", "a programmer", "fun"]
random_about_me_choice = rand(about_me.length)
@about_me_choise = about_me[random_about_me_choice]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a fun ruby way to do this:

First, no need to use "Array", you could do

about_me = ["a human being", "female", "a programmer", "fun"]

Then, to randomly pick something out, you can reduce that to:

@about_me_choice = ["a human being", "female", "a programmer", "fun"].sample

#sample will shuffle the array and pick the first item. fun!

@jwo
Copy link
Member

jwo commented Apr 29, 2013

Sure, I think it works. I would probably like to see the duplication removed between the "/" and the "/about" --- like have that code be a method you can call.

get '/' do
  @about_me_choice = random_fact
  erb :about
end

get '/about' do
  @about_me_choice = random_fact
  erb :about
end

# ... later

def random_fact
  ["a", "b", "c"].sample
end

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants