r/learnruby • u/[deleted] • Jan 05 '21
r/learnruby • u/Makan_Lagi • Mar 04 '15
Protyping some finance software - is Ruby the right way to go?
So I'm not an engineer at all but took an online course for Ruby on Rails in the past so I could build some prototypes of concepts I've had. Right now I'm working on something for my team that's finance based and it all lives in Excel / Dropbox. It's a way for my team to track expenses and categorize everything. There's multiple services we use from our credit cards, travel, and paying off vendors so trying to get a report on our budgets is a hassle.
I want something that can handle multiple users, and the users would be able to just fill out a form for each payment entry, categorizing into things like "labor," "travel," etc, along with other fields like the date, notes or reference number. Then I want to be able to run reports or have a dashboard that takes that employee's entries and subtracts it from the budget we have set for each of those categories.
Can anybody point me in the right direction of what gems I could use to put something like this together? Or am I an idiot and going about this all wrong and need to pay somebody for it ;)
Thanks!
r/learnruby • u/moomoocow88 • Apr 01 '13
Trying to understand how to round decimals
So I'm a total beginner (started today) and I've written a very simple script to calculate the percentage change of one number to another. The problem is, the answer sometimes has like 10 decimal places. I've tried using .round(2), to get it to two decimal places, but it doesn't work. Can anyone help me?
This is my script:
puts "Percentage Change"
puts "Please enter original number"
value2=Float(gets.chomp)
puts "Please enter new number"
value1=Float(gets.chomp)
perc = value1 / value2
perc.round(2) #This is what I tried to use to get it to two decimal places, but it doesn't work, it is just ignored
if perc<1 puts "Uh oh! Looks like your number has gone down! Your percentage change is #{(perc*100)-100}%"
elsif perc>1 puts "Yay! It looks like your number has gone up by #{(perc*100)-100}%"
else puts "Your number has not changed"
end
r/learnruby • u/MattsFace • Feb 02 '14
Can some one explain what is going on here?
What exactly is going on here? I was going fine until they made an array the default value!
hash = Hash.new([])
hash[:one] << "uno"
hash[:two] << "dos"
hash[:one] => ["uno", "dos"]
hash[:two] => ["uno", "dos"]r/learnruby • u/macky6 • Nov 05 '18
How to map an array only for a limited number of matches
Hi, I'm trying to make changes on an array with the map function. So as an example:
a = [1,2,3,4,5]
a.map! { |i|
if i>2
0
else
i
end
}
p aThis results in [1, 2, 0, 0, 0] as normal. But what should I do if I want it to work for only two matches of i>2 and give me the result [1,2,0,0,5]? Is there a method for this? Any suggestions would be really helpful.
r/learnruby • u/soonerguy9782 • Sep 26 '12
Ruby noob. Trying to write a simple to do app...
I am trying to write a simple to do app but i'm struggling. The display function doesn't work and neither does the if in the main loop. Please help, I've been on this for hours. sigh http://codepad.org/1j7yOMaa
Edit: as far as the exception, that's because it is in codepad. The problem that I have is that it doesn't run any of the todoList methods and in the main loop the ifs never execute.
r/learnruby • u/SunnyDLuffy • Oct 24 '14
Beginner practice on the go / over short amounts of time?
A little background: This is the last year of my undergrad (bio major) and I'm looking to get into Ruby. I'm in the super early stages of learning (Codeacademy/various tutorials). It's a lot of fun and I really enjoy it, but the biggest challenge is finding the time to do it every day because I have to prep for the next day each night. I am able to set aside 10-12 hours on the weekend, but I'd like to be more consistent throughout the weekdays.
I've tried listening to some audio tutorials while in lab or just thinking about what I learned, but the latter often becomes hard (I tend to be unsure of 60-70% of what I learned if I don't practice). If anyone has tips on how they practiced on the go or while eating (~45 minute or so breaks) I'm all ears. Unfortunately I don't have a laptop.
Thanks for the help!
tl;dr: Any tips on how to study/practice on the go over short periods of time (without a laptop)?
edit: I did a bit of looking around and found that maybe books that don't require a laptop/computer would be a good avenue. I really hate reading, but this is definitely something I'm interested in.
I read up some reviews on Well-grounded Rubyist and Eloquent Ruby; people said that both of these should not be an "intro" book. Would I be able to get through either of these after finishing the Codeacademy course? Any recommendations of which one to get?
r/learnruby • u/RealityShowAddict • Jan 14 '16
Blocks are Super confusing... Suggestions?
Hi,
I am struggling to wrap my head around the concepts of blocks. Is there something similar to this in either Java or C#?
This seems to be an amazingly powerful concept, but I just can't figure it out how to use them in code I write.
Thanks in advance.
r/learnruby • u/slacker87 • Aug 14 '14
Ruby on rails beginner skype group
We have a small RoR beginner programming group on skype that we'd love to have a few more contribute to and join. Ask questions or show off your current project your learning on! We idle in the room just about all day and questions get answered pretty quickly.
Interested? Great! Send me a skype invite @ racethesunlive and i'll toss a group chat invite your way.
r/learnruby • u/SdotRemedy • May 21 '15
Eloquent Ruby
I just recently finished the Codecademy ruby course. I was wondering if Eloquent Ruby by Russ Olsen is a good next step? If not, what books or other resources would be a good next step?
r/learnruby • u/zanity84 • Apr 02 '12
Writing app with Shoes that works with Active Directory
Hello,
I am far from considering myself a programmer, so please forgive my noob-ness. I am interested in learning the basics of Ruby to eventually create a simple application using Shoes that will query our domain controller. I found an AD module, found at http://activedirectory.rubyforge.org/, that seems to be helpful. However, I am having difficulty understanding where exactly to put all necessary information on the script itself. I'm not needing to use Rails but rather a stand-alone app. Any help or insight in the matter will be greatly appreciated! Thanks,
Alex
r/learnruby • u/[deleted] • Jul 08 '16
My first ruby project...
So, I've dabbled in programming a little in the past. I picked up a book on ruby and really loved how everything worked.
As a learning exercise, I decided to make a create your own adventure type console game. I would really love some feedback on what I could do to make my code cleaner, more efficient, etc.
You'll need the artii and cli-colorize gems to run it, if you want to run it.
Here's the code: https://repl.it/C8fZ/29
Please be gentle... =D
r/learnruby • u/AnnaBodina_VNNV • Jun 09 '21
Ruby Frameworks
Ruby is a programming language that has been accepted with open arms since 1995, and thanks to its open-source nature, it is still growing every day. Ruby is fast, object-oriented, and secure, which brings a dynamic nature into the project with an MVC support structure that makes development more comfortable than ever. With start-ups openly accepting Ruby, the language has shown remarkable progress in almost every field, especially web development.
Ruby’s popularity motivated people to take the development to the next level and bring out some best ruby frameworks for the developers. Some frameworks are built to ease out middleware and request/response of the application. Some are made for REST APIs and others for web applications. Collecting the best ruby frameworks from across the globe, in this post, we’ll talk about these frameworks and how each framework lets the developer take advantage of Ruby.
Without further ado, let’s delve into details of the best ruby frameworks for web development that will surely benefit your business.
r/learnruby • u/CodeTinkerer • Apr 24 '18
HackerRank: 30 Days of Code: Prereqs
Link to 30 Days of Code: https://www.hackerrank.com/auth/login/30-days-of-code
Next day: https://www.reddit.com/r/learnruby/comments/8ethsr/30_days_of_code_day_1_hello_world/
HackerRank is a coding website. They've been doing 30 Days of Code where you pick a language they support, and go through 30 program exercises. I figured since this subreddit gets few posts, I'd go through the exercises for those new to Ruby.
Ruby was invented around 1995 by Yukihiro Matsumoto, or Matz, for short. Ruby's popularity hit its peak probably around 2006 or so with Rails, a web framework written in Ruby. It's often compared with Python, which is a similar language.
Data Types
I'm going to start with 3 data types in Ruby. There are integers, which are whole numbers with no fractional part. Examples: -100, 2, 1999. Note that integers do not contain commas for numbers 1000 or greater. Ruby does allow underscores instead of commas, but many programmers just write the entire number with no underscores.
There are float numbers. Float stands for floating point numbers which are basically rational numbers written in scientific notation. Put more simply, they are numbers with a fractional part. Examples include 3.14, 900.0, -0.001 etc. A float that looks like an integer, say, -9.0, is represented differently in computer memory than -9.
The third type we'll start off with is string. A string represents some text. In Ruby, you can write strings using single quotes as in
'cat'Or double quotes as in
"cat"The quotes tell Ruby that you have a string, and indicate where a string starts and ends. The quotes aren't part of a string. So, a string cat contains 3 characters. The default encoding for Ruby strings is UTF-8.
A little history. As you may know, computers store data as numbers, even text data. ASCII was a common encoding. It used 7 bits (stored in a byte, which is 8 bits) from 0 to 127. The problem with ASCII is not enough numbers to encode foreign characters, esp. Asian characters. So, UTF was created to replace ASCII. UTF is strange because it has a notion of codepoints. Each character in UTF has its own codepoint. UTF can encode that codepoint in different ways depending on UTF encoding. For example, UTF-16 (I believe), uses 2 bytes for every codepoint. UTF-8 uses a variable number of bytes, from 1 byte for some codepoints up to 4 bytes. UTF-8 has basically "won" because for the codepoints associated with ASCII, UTF-8 has the same encoding. So, if you have a legal ASCII string, it's also a legal UTF-8 string.
Anyway, that's way too technical. Let's get back to simpler stuff.
Strings don't have to contain words from the dictionary. You can write:
"askjaijwe"You can have spaces: "This is a string".
You can have strings that look like numbers: "123"
Strings that look like numbers aren't numbers. You can't do math with strings (like adding, subtracting, multiplying, etc.).
There are other data types, but for now, we won't get into them.
Variables
When you write a program, you are dealing with data, whether they be integers, floats, or strings. You need some place to store the data so you can refer to them or manipulate the data. In Ruby, as in many languages, variables are used to store data.
How do you put a value in a variable? You use an assignment statement.
Here's how it looks:
val = "cat"Variable names (in this case, val) must consist of digits, letters (upper or lowercase), and underscores. The first character in a variable must not be a digit (makes it easier to distinguish numbers from variable names).
A variable has a memory location, a name, and a type/class. When you see
val = "cat"A string "cat" is created and placed in the memory location called val (think of a memory location like a mailbox which has an address and contents, in this case, the content is the string, "cat").
Some languages force variables to have an explicit type (e.g., it's a String variable), but not Ruby. For example,
val = "cat"
val = 4The first line places the string, "cat", in the memory location of val. The second line places the Integer, 4, into the memory location of val (it's actually a little more complicated than that, but will be explained later).
People usually say val is being assigned to the value, 4. However, I prefer to say val is being updated with the value 4.
Output
To me, a program consists of input and output. Input is data from the outside world that gets fed into a program. This could be user input (someone typing some stuff), or it could come from a file, or maybe a game controller, or maybe a remote file from the Internet. These get fed into variables that the program can look at and manipulate. Output is information sent to the outside world, such as text that appears in a screen, or an output file, or a sound, or visual effect, or some message sent via the Internet.
The most basic output of most programming language is text sent to something called the console. The console is a screen. Think of it a little like the screen where you receive your text messages. If someone messages you, the text appears on a screen on your phone. That screen is basically what we're calling a console.
In Ruby, there is a function that lets you send a value to the console. It is called puts. This is short for "put string", and its name comes from C which has a similar function (though C prefers printf).
This is how you might use it
puts "Hello, World!"This sends the string Hello, World! to a console. Printing is considered output. Information goes from the program to the outside world. puts also adds a newline (basically, the same as hitting the Enter key) after the string. If the string already has a newline at the end (we'll talk about how that could happen later), then it won't output an additional newline. To emphasize, the newline is a character whose action is to act like the Enter key was pressed (thus causing the cursor to move to the start of the next line).
You can also use puts on a variable, as in
s = "Hello, World!"
puts sIn this case, when Ruby sees a variable, it replaces it by the contents of the variable, which is the string "Hello, World!".
Note that puts is the name of the function, and s is the argument. An argument means a kind of parameter. For example, suppose you wanted to order a pizza. Someone asks "What kind?". You say "mushrooms". Mushrooms is an argument, that is, some additional information needed to make a pizza. In this case, s is an argument to the function puts which indicates what should be printed.
In many languages, parentheses would be required for the arguments. In Ruby, it is optional, especially for functions that use a single argument. You could also write
puts(s)That would do the same thing.
Object IDs
In Ruby, most everything is an object. We'll talk more about objects later, but one useful (though obscure) fact is that objects have an object ID. In the US, most people have their own social security number (SSN) that uniquely identifies them. In Ruby, think of the object ID as some number that uniquely identifies an object. No two active objects have the same ID.
Sometimes object IDs are called references or pointers. However, I prefer calling them object IDs, even though this is not so common.
In Ruby, variables basically store object IDs. This is important for the following reason. Consider this code:
s = "cat"
t = sIn this first line, we appear to put the string cat into the variable s. That's not exactly true. cat is an object and has an object ID. For sake of example, let's pretend this ID is 25. Thus, s contains 25. When you write something like
puts sIt sees the object ID, 25, but it knows to print what the object is which is the string, cat. Thus, 25 is associated with the string cat. Now, look at this:
t = sThis takes the value in s (which contains the object ID, 25), and copies it into t, so t now has 25. If you do
puts tIt will see t contains 25, and find the associated object, namely, the string cat and print it.
If s had contained the string cat, and not the object ID, then
t = swould make a copy of the string, so that the string t has and the string s has would be "different". It's as if Tammy and Sue had two copies of the same book. They don't have the same book. If Sue writes in her book, Tammy's book is left unchanged.
However, with object IDs, both t and s have the same object ID, thus, refer to the same object.
Hello, World!
Finally, we repeat a program that is considered the first program in many languages, which is printing Hello, World!. In Ruby, this looks like
puts "Hello, World!"Next time
I'll introduce the first program in the HackerRank 30 Days of Code and talk about its solution.
r/learnruby • u/VolvoDonkeyPunch • Apr 14 '14
FizzBuzz
I was looking at fizzbuzz examples and I wrote my own today. I wanted some feedback and see if there's anything I can do to improve my code. Also interested in seeing other people's examples!
Here's my code:
def fizzbuzz(count)
(count+1).times do |num|
print "Fizz" if num%3 == 0 unless num==0
print "Buzz" if num%5 == 0 unless num==0
print num if num%3 != 0 && num%5 != 0
puts ""
endr/learnruby • u/Irakaj93 • Dec 28 '20
Why is recursion so hard!!!
I’m learning Ruby through App academy’s free online course. And man is it hard! I don’t know how long it will take me to get through this. But I’m on Recursion right now. Does any know what are the best ways to practice this? I find myself falling behind schedule because I can’t solve the coding problem.
Any pointers are welcomed.
r/learnruby • u/SupremeDesigner • Jun 04 '16
Basic Friendly Coding Help /r/CodingHelp
Hey guys,
So I know this a great sub for all things programming related, but I thought I'd just pop in and mention our new sub /r/CodingHelp
Over the last few days we have revived it and now have over 1000 subscribers already! Please come and check it out if you want some free, friendly and easy to understand coding help!
Mods, if this isn't allowed, sorry, please remove it
r/learnruby • u/roelofwobben • Jan 13 '19
VSCode or Atom
Hello,
I like to do my first steps on the Odin project.
Can I better use Atom or VSCode on Windows.
and are there tutorials how to set them up
Roelof
r/learnruby • u/aakhya • Jul 05 '16
New course on Ruby at CodesDope to learn Ruby from scratch in the simplest way
Hello,
Ruby is a programmer's best friend and is a very simple and friendly language. We have made learning it even simpler by introducing a new course on Ruby at CodesDope.
At CodesDope, we believe that in learning, your passion is your motivation. Our main objective is to make learning so simple that even those who have absolutely no background in coding can learn it in a reasonable time-period.
There are also topic-wise practice questions in its practice section so that you can learn to apply the concepts just after you have understood them. You won't find much questions for practice for Ruby elsewhere, unlike other programming languages. Last but not the least, there is also a forum for discussion each and every doubt - big or small - that you have so that you can also remain in touch with us 24/7, or at least as frequently as possible.
Just go through the content and practice questions and believe me, you will just start loving coding!
The course link is : http://www.codesdope.com/ruby-introduction
r/learnruby • u/stanislavb • Aug 01 '16
Awesome Ruby - A curated list of awesome Ruby gems
ruby.libhunt.comr/learnruby • u/twink780 • Sep 29 '14
Anyone website with small ruby projects?
I just want to see some simple/small ruby projects that are done.. just to see/read and get a hang of Ruby more and to see how its all put together as a whole.
r/learnruby • u/yez • Jul 23 '15
Ruby on Rails enables a lack encapsulation. But you don't have to.
jakeyesbeck.comr/learnruby • u/AnecD • Jan 20 '19