r/learnruby • • Oct 30 '14

Can't get variables to work in Powershell

0 Upvotes

Hi, I am following along the Learn Ruby the Hard Way book and I am having some trouble with Powershell. I have gotten Ruby running in the shell and I can perform calculations and run .rb files. However, when I try to do a simple variable assignment such as:

i = 4    

I get a large red error message saying something along the lines of "i : The term 'i' is not recognized as the name of a cmdlet, function, script file, or operable program etc..."

Why is it trying to read this as a script/program name instead of a variable assignment?

Using Ruby 2.0.0p576 (x64) on a 64 bit Windows 8 machine if that helps at all.

EDIT: I also realized that it won't allow me to even do basic comparisons like 4 == 9. It tries to read that as an assignment for some reason.


r/learnruby • • Dec 18 '15

I Graduated From a Code School. Now What?

Thumbnail kcoleman.me
0 Upvotes

r/learnruby • • Feb 07 '14

EL15: How would you explain constructing a code in Ruby and how would you teach Ruby to five-year olds?

0 Upvotes

Here's the issue I'm facing. Most programmers can view something like SAMPLE CODE and understand what that means even being able to write that back into plain english what the code does. My problem is the opposite which is converting a pseudocode into these codes; taking, in plain english, of a problem and attaching the Ruby language to solve and execute it.

If there's a patient sensei who's in NYC that would take a pupil under his/her wing! I'll be a great friend.


r/learnruby • • Mar 20 '14

gets.chomp? code academy why am I passing?

1 Upvotes

ok i think i under it as gets.chomp takes the : print "what's your first name?" first_name = "bob" variable_name = gets.chomp the bob become a variable so what i don't get is why isn't it being reconized or what i am doing wrong here using codeacadimiy I am passing the test but, I just dont think I should be here with what i am puting down

http://imgur.com/7FsE6Np

I think it should be outputting: my name is, my city is....

but it isnt


r/learnruby • • Feb 18 '14

Learning Ruby - a reminder to write the test first

Thumbnail perezish.com
1 Upvotes

r/learnruby • • Oct 05 '18

free tutorials

1 Upvotes

I am looking for a list of 'free' online courses for Ruby.

I tried codeacademy and didn't like the course, (it teaches me a terrible way to do what .reverse! can do), and a few other things that seem silly to me.

I bought a udemy course, and it skipped classes :( and was SUPER quick to go over anything and now I am frustrated.

Looking for some guidance and assistance in learning.


r/learnruby • • Jun 26 '14

One Month Raises $770K To Teach All Of The Coding

Thumbnail
techcrunch.com
3 Upvotes

r/learnruby • • Jan 23 '13

Saving files in memory?

0 Upvotes

I have some code that creates a file on disc, emails it and then removes it. I just feel there should be no reason to write it to the disk.

Is there anyway to save the file in memory?

temp_file = 'path/to/file.csv'
users = [[email protected], [email protected]]

CSV.open(temp_file, "w") do |csv|
  csv << data_for_report
end

Reports.sendreport users temp_file

File.delete(temp_file)

r/learnruby • • Feb 22 '13

How does class redefinition work in Ruby inside a module?

0 Upvotes

I'm working with Net::HTTP and the disparities between 1.8.7 and 1.9.3 caused me to realize something I hadn't learned about. Consider the following:

# 1.9.3
require 'uri'
require 'net/http'

uri = URI(url)
req = Net::HTTP::Get.new uri.request_uri
http = Net::HTTP.start(uri.host, uri.port, :use_ssl => (uri.scheme == "https"))
response = http.request req

This allows me to make an SSL call regardless of whether I have required 'net/https'. In 1.8.7, I have to do:

require 'uri'
require 'net/http'
require 'net/https'

# snip
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == "https")
response = http.request req

The thing is that by requiring 'net/https' very little is done and it's all done on the same class, i.e., lib/net/http.rb looks like:

module Net
  class HTTP
    # etc
  end
end

And lib/net/https.rb has the same structure. How does the second simply add features to the first without overriding it's definition? I guess the proper name for this would also be helpful so I could Google it and learn more about it.

Thanks in advance


r/learnruby • • Feb 23 '13

Bytes: Reading from/writing them to a file

0 Upvotes

What would be the best method to read bytes from a file to store in a variable, modify, then overwrite in the same file?

I'm mostly working with signed 16bit integers, which take up two bytes. The method I'm using now is:

 @file = File.new("file", "r+")
 @file.seek(0, IO::SEEK_SET)
 @bytevariable = @file.readbyte + @file.readbyte
 @file.seek(2, IO::SEEK_SET)
 @bytevariabletwo = @file.readbyte + @file.readbyte

Ugly, and those aren't the variable names I'm using, but that's basically it. That seemingly does work, but it seems very hack-ish and will probably end up breaking.

When I try to overwrite the bytes with something like:

 @bytevariable = 50
 @file.seek(0, IO::SEEK_SET)
 @file.print "#{@bytevariable}"
 @file.close

It messes the file up.

From what I've gathered I might need to look into the unpack and pack methods, but I was wondering if anyone could explain those, what I need to do, and any other suggestions about the code/method.


r/learnruby • • Apr 21 '13

Ruby is too slow for programming competitions

Thumbnail blog.clifreeder.com
0 Upvotes

r/learnruby • • Oct 08 '14

Is this RoR SaaS course on edX the "best" MOOC available to learn Ruby?

Thumbnail
edx.org
0 Upvotes

r/learnruby • • Jul 04 '13

One Month Rails [build a web app in a month] stop waiting for the perfect technical co founder, and build it yourself - in case we needed more learning resources

Thumbnail
onemonthrails.com
0 Upvotes

r/learnruby • • Aug 15 '14

Website with Ruby examples?

0 Upvotes

I am having trouble learning classes and methods. I think I understand them, but don't feel comfortable with them. Can anyone recommend some helpful websites that provide examples? (I am a beginner to programming in general)


r/learnruby • • Mar 31 '21

[HIRING] Do You Think The Economy is Destroyed? Think Again!! We Need You!! We Have More Than 20 Ruby Jobs!

Thumbnail docs.google.com
4 Upvotes

r/learnruby • • Apr 22 '14

10 Reasons Beginners Should Learn Ruby on Rails

Thumbnail
blog.onemonthrails.com
5 Upvotes

r/learnruby • • Oct 27 '14

Why does ruby re-order a defined hash?

1 Upvotes

I created a hash (below) and want to iterate through it from left to right. As you can see from the output, it's rearranged itself (and it doesn't appear to have a logical order). What's up with that?

change = {25 => 0, 10 => 0, 5 => 0, 1 => 0} 
p change
{5=>0, 1=>0, 25=>0, 10=>0}
=> nil

r/learnruby • • May 15 '15

Logging into a server using Basic Authentication and JSON with rest-client

1 Upvotes

I'm having some trouble trying to figure out how to log into a server using the external API that is provided. The documentation states: To login over REST, the following call would be issued (with request header Basic (base64encoded username:password)): https://serverIP/folder/folder2/login Here is my sample code. I've seen you can pass :username and :password but I can't tell if I need to encode both of those values separately or pass them as a single string. Any advice or tips is very much appreciated. Sample code:

#!/usr/local/bin/ruby

require 'rest_client'
require 'base64'
require 'json'

auth = 'Basic ' + Base64.encode64( 'USERNAME:PASSWORD' )

RestClient::Request.execute(:url => 'https://ip/folder/folder2/login'', :method => :post, :verify_ssl => false)

r/learnruby • • May 15 '14

Interview with Obie Fernandez author The Rails Way & co-founder Hashrocket at RailsConf 2014

Thumbnail
ugtastic.com
1 Upvotes

r/learnruby • • May 23 '14

Learning Ruby in Ubuntu. What version should I use 32bit or 64bit?

0 Upvotes

I come from a Windows background and would like to know which version of Ubuntu would be easier to install and run Ruby in?


r/learnruby • • Sep 05 '14

Python has very "pythonic" ways to solve problems. Does Ruby have "Rubaic" ways to solve problems?

1 Upvotes

I'm a python man. I love, eat, sleep and breathe python3.x. I mainly used it to data-mine. Recently, an internship opportunity has required me to learn the ways of Ruby.

My question now is this: Is there a "right" way to solve problems. Especially problems related in the field of webscraping?

Anyways, that's really it. Thanks for helping out!


r/learnruby • • Jan 20 '19

Ruby as a scripting language to master OOP?

Thumbnail
reddit.com
1 Upvotes

r/learnruby • • May 02 '18

Question about scoping in Ruby? (with example from Rails)

1 Upvotes

A Rails project has lots of configuration scripts (like config/environments/development.rb) that start with the line

Rails.application.configure do

I'm trying to figure out what's happening here, and so far I know that Rails.application.configure seems to be a method call that is passing a do block as an argument. And I think application is some instance of a class that has a configure method to call. But where did Rails come from? There weren't any statements like require or 'load' preceding the method call, so I'm just confused about how Rails entered the namespace/scope for this script?

Thanks!


r/learnruby • • Dec 22 '15

Clarification on why I have to use $end instead of just end in this codeacademy problem.

1 Upvotes
my_array = [1, 2, 3, 4, 5]
x1 = 0
my_array.each { |x| puts x1 = x * x }
end

fails to complete the task of having a block that squares each value in the array, syntax error message hinted that I needed "$end" instead. Up until now I've not needed to use it and a quick google search just tells me that $ is used for global variables. I'm not sure "end" is a variable but rather a required syntax. (My terminology is probably off but I hope I come across as understandable). Thanks.

my_array = [1, 2, 3, 4, 5]
x1 = 0
my_array.each do |n|
x1 = n * n
puts x1
end

This example worked without needing the $ preceding the "end". To my limited understanding they are both identical and just different styles?


r/learnruby • • Feb 15 '16

Getting the parameters of a method

0 Upvotes

Given:

def foo(a, b, c)
end

How do I get the values of a, b, c?. I cannot find this anywhere.