Skip to content

Conversation

@dramanat
Copy link

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

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