A Brief Overview of Ruby

Iterators

  • Iterators make it easier to write code
5.times do
  puts “hello”
end
  • Integers/floats: times, unto, down to, step
  • Range: each, step
  • String: each, each_line, each_byte
  • Array: each, each_index, each_with_index
  • Hash: each, each_key, each_value, each_pair

Methods

  • Values are passed in when they are called, and they are sometimes abbreviated as args
  • Operators are also methods in ruby
  • Syntactic sugar refers to simplifying the code
  • Syntactic vinegar – not so tasty code
  • Methods are all lowercase with underscores

Classes

  • Classes use camel case (they always start with a capital letter): SomeName
  • Classes group the code into discreet, well-categorized areas
  • Can define methods inside a class
class Animal
  def make_noise
    “Moo!”
  end
end
animal.make_noise
  returns “Moo!”
  • make_noise object is created from the class and then we can tell it to do things
  • Objects let us organize code into well-categorized areas
  • Allow complex behaviors using simple statements
  • Instance: an object created from a class
animal = Animal.new
puts animal.make_noice
  • Animal.new is an instance which is an object
  • .new is a class method

Instance Variables

  • Instance variables start with an @ symbol – @variable
  • Instance variables are used within the instance of a class
  • Allow us to keep track of attributes
  • Never have access to instance variables from outside the instant
  • We can access methods within instance, so need to use methods to get instance variable
  • Setter methods – sets a variable equal to value
  • Getter methods – getting that value back

Attribute Methods

  • Methods that we put into classes – takes symbols and turns them into methods
    • attr_reader
    • attr_writer
    • attr_accessor (creates a reader and a writer method)

Additional Terms

  • Instantiated = creating a new instance
  • Class Method – a method that can be called on a class even without an instance of the class
  • Class attributes – store values that apply to the class generally stored in a class variable @@variable
  • Instance variables are only inside the instance
  • Inheritance – inherits the methods and attributes of another class
  • Can only inherit from one super class
  • Modules are wrappers around classes

Getting Started with Rails

For anyone that’s new to Rails, there are a couple of tutorials out there that I’d highly recommend:

I’d say repeating the Rails Guide tutorial several times first is a good place to start, then moving to Michael Hartl’s tutorial and completing that a few times, which will give you a much better understanding of even more complex Rails concepts.

I’m a strong advocate for learning through repetition, especially if you’re new to programming or don’t have a background in computer science.

WDI Day Fifty-Six: Project Week 4, Part 4

My project is gradually coming together, and I’m feeling much better about things now that I’ve changed gears. I’ll definitely need to revisit front-end frameworks next week so I can feel more confident with them.

After spending a few hours working on my app, we had a break in the afternoon where the Outcomes team had a former instructor review the technical interview process that developers often go through. Since I’m not at all familiar with that process, it was pretty insightful to get a taste of what happens.

Later I played around with adding animations to my app, and discovered how fun SVG animations are. I’ll need to look into those more in-depth since they seem to be pretty powerful. Overall, today had several wins. I managed to set up user logins, deploy my app, add image uploading with AWS, spiced up the homepage with an animation, and looked into a few other ways to fine-tune the app. For tomorrow, I hope to work on the following:

  • Adding icons to each landing page
  • Rethink the puzzle index page
  • Rework the styling
  • Try to resolve the offset issue that makes the JavaScript puzzle act weird in Chrome and Firefox
  • Add seed data
  • Fine-tune the user experience for user logins

WDI Day Fifty-Five: Project Week 4, Part 3

I woke up at around 5am today to get started on rebuilding my project since I only have until Friday to finish it. I want to make sure that I can create as complete of an application as possible. I like how when my instructor heard that I was rebuilding my project, he told me that the deadline is really just an arbitrary date since we aren’t getting graded for the final project. But I told him that I still wanted to create something complete and portfolio-worthy. And that I can always revisit these more complex applications next week, when I don’t have the pressure of a deadline – even if the deadline is considered arbitrary.

I redid my application in Rails and managed the get the JavaScript puzzle functionality working, for the most part, as I’d like it to. Tonight I’ll work more on styling the application and fine-tuning the JavaScript functionality. Tomorrow I think I’ll add user login and launch it for the first time to see how it does live. Then I’ll take a look at some smaller “like to haves” that I’ll work on tackling one-by-one.

Ever since our third project, the group one, I’ve found myself feeling a little down about my abilities as a developer. I’ve been doubting myself a lot lately, and I’m realizing the problem is that I’m dealing with too many complex frameworks and concepts. Every now and then, I think it will be a good idea if I revisit concepts and technologies that I’m more comfortable with so that I can reassure myself that I am perfectly capable of building things. Sometimes it’s easy to get lost in the noise of all the languages and techniques that are out there. It’s a good thing to reevaluate where you stand.

WDI Day Thirty-Three: Project Week 2, Presentations

After an exhausting week of trying to get things to work, have things break, and also find myself unable to complete a few ‘nice-to-haves,’ I somehow made it through it all with a functional app that looks nice.

Today we worked on finishing touches for our applications. We also did screencasts of our apps to demo them. It was my first time ever making a screencast, and I’ll definitely need to do more of these in the future. Anyway, here’s mine:

I was really excited that this morning I managed to resolve my whole sending an image to the database issue. It was funny how I was almost in disbelief when I got it to work. Apparently I stared at my screen for a while and said, in disbelief, “I got it.” Everyone who was coding in the room cheered and high-fived me. They can definitely relate to how amazing it feels when you resolve an issue that seems impossible.

Later this week I hope to tackle some of my other unsolved problems. But for now, I’ll take a break and rest from this whole coding thing – I want my mind to definitely stay sharp.

mapsketch-screenshot

WDI Day Thirty-Two: Project Week 2, Part 4

Today proved to be another day of frustration. I spent the majority of the day tackling the encoding/decoding issue with images. I managed to resolve one major issue, where the Google API was throwing errors when trying to encode the canvas with the Google static image map, so I was able to create a string for the encoded image. However, I ran into the problem of being able to submit that string to the database. I tried hiding an input field where I changed the value to the encoded string and also tried to create a new field with the new value on submit of the form, but still no luck.

I did manage to resolve an issue with the drawing tool so that users can create different strokes in different colors. I also made a few UI adjustments, yet overall, it was a day of frustration that involved a lot of error and not too many breakthroughs. Perhaps tomorrow will bring with it some better insight?

WDI Day Thirty-One: Project Week 2, Part 3

I’ve been working like crazy, and some issues are issues that I don’t know whether or not they can be resolved. Overall this web app project has me realizing how important the planning process is. You may have a great idea, but you might want to test out a couple of things before moving forward with it.

Our projects are due on Thursday morning, so I have one more full day and night to work on my app. At the moment, it’s functioning and I’ve styled it so it nearly looks the way I’d like it to. I’ve also deployed it to Heroku so everything looks like it will function alright in production. Tomorrow night I’ll work on creating a screencast of the app, so until then, I’ll have to try to get everything ready to launch.

Goals for tonight:

  • Possibly roll out a many-to-many relationship where users can create lists.
  • Look into submitting images to a database. I’ve been struggling with this issue and have decided to put it to the side for now. I’ll visit it later to see it I can roll it out. If so, it would make the user experience a lot more seamless.

Goals for tomorrow?

  • Look into using ActionMailer for email confirmations.

WDI Day Thirty: Project Week 2, Part 2

Today was the second day where we got to work on our project 2 all day. In the morning there was a mini lesson on APIs and Rails, but after that, it was nonstop coding. What’s pretty unfortunate is that I didn’t make much progress. I’ve run into a couple of pretty large and advanced problems that my instructors haven’t been able to help me with.

One issue is that I need to figure out how to capture a screenshot of a webpage and then submit it to the database on submit of a form. The other issue is making calls to the Google API in order to change the background image of a canvas element on the page.

When you don’t make any progress, it’s tough to stay motivated and try to keep pushing forward to see what happens. Hopefully things will look better tomorrow. All I can do is keep trying new things, and hope I’ll eventually get the right results.

WDI Day Twenty-Nine: Project 2 Kickoff

After a long week of building CRUD app after CRUD app in Rails, today our Project 2 Week was kicked off with an intro to the project requirements. I’ll have to build an app in Rails that uses at least two models with at least one association, have complete RESTful routes, have error handling & validations for all resources, and utilize an ORM to create a database table structure.

I pretty much built the bare bones for my app at the beginning of the week as we went through learning CRUD. So today I worked on cleaning up my older code, adding a user login, styling the app a lot so I can get some inspiration on where to take it (for some reason when things look nicer, I get more motivated), and created another model.

My project is a pretty ambitious one, so I’m not sure if I’ll be able to build it entirely. It’s a drawing app, where users can draw on maps. It utilizes the CRUD functionality, but one of my biggest challenges will be to figure out how to store the images that users create. I’ve nearly completed the drawing functionality with JavaScript, and have figured out how to save the drawings as images. Another challenge is that I’d like to figure out how to implement Google’s image map API so that I can change the canvas background image dynamically to whatever location a user is interested in seeing.

Here’s a screenshot of my work in progress:

WDI Day Twenty-Eight: Testing with RSpec, Many to Many Relationships, & CRUD

We briefly got an overview on setting up tests with RSpec. The syntax was a little strange to me, and I’m realizing I really need to dive back into older things we covered just to ensure I’ve got a good grasp of everything. I won’t have a chance to do that this weekend since I have to work like crazy on my second project, but once that’s done with, I’m looking forward to reviewing things we covered earlier. Later we did a few exercises with many to many relationship models. I understand the concept, it’s just the actual use of this is something that will take some time for me struggling on the side with it. Once the lessons were over with, I worked like crazy on my homework assignment. Here’s a screenshot of the welcome view: coffeecheck-screenshot I had a lot of fun putting it together, but I probably spent more time than necessary styling it. And now I’m off to start working on my second project, so hopefully I”ll be off to a good start.

Project Details:

Ruby on Rails app will CRUD functionality where users can add, update, and delete coffee shops and coffee drinks. View the project

Technology Used:

  • Ruby
  • Ruby on Rails
  • psql
  • Heroku