Learn Geek languages like Big data,Hadoop,Hive,Pig,Sqoop ,flume,Cassandra,Hbase,Ruby On Rails,Python,Java and many more.

Friday 24 June 2016

Installation of ruby

1.tar your ruby-2.3.1.tar.gz in root
2.go to ruby-2.3.1 folder in root
3 than run these commands
>>  ./configure
>> make
>> make install

Installation of rvm

1.tar rvm-1.27.0.tar.gz
2.for set the path ,write this following command
 >> sudo gedit .bashrc
paste this line in your .bashrc file
 export PATH=$PATH:/home/ratul/ruby/rvm-1.27.0/bin
3.rvm automount
 it will ask for give the name, mention any name
4.rvm use --default
5. rvm list

Installation of Rubygem

1.unzip your rubygem-2.6.4.zip
2.move into root by
>>sudo su
3.go to rubygem directory
4. run command
>>ls
5. you can see the file setup.rb
6. now run
>>ruby setup.rb


FOR FURTHER QUERY
Contact On  :  +919814040990
# use of class in ruby program

class Abc
attr_accessor :a1, :ans
def initialize (a1,ans)
@a1 = a1
@ans = ans



def ask
   puts "Question #{a1}"
a = gets.chomp


if a == "#@ans"
puts "correct"
else
puts "wrong, answer was 8"
end
end
end
end
a=Abc.new("what is 3 + 5","8")
a.ask

OUTPUT:

Question what is 3 + 5
4
wrong, answer was 8

#display An Array

the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'apricots']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']



#OR
for number in the_count
  puts "This is count #{number}"
end
#OR

the_count.each do |number|
puts "no. are   #{number}"
end
#OR
fruits.each do |fruit|
  puts "A fruit of type: #{fruit}"
end
#OR
change.each {|i| puts "I got #{i}" }

# OR
fruits.each {|i| puts " list of ::#{i}" }

OUTPUT:

This is count 1
This is count 2
This is count 3
This is count 4
This is count 5
no. are   1
no. are   2
no. are   3
no. are   4
no. are   5
A fruit of type: apples
A fruit of type: oranges
A fruit of type: pears
A fruit of type: apricots
I got 1
I got pennies
I got 2
I got dimes
I got 3
I got quarters
 list of ::apples
 list of ::oranges
 list of ::pears
 list of ::apricots

# random index value of array in ruby program

def que_ans

q=['What is 8+6?','What is 5*4?','What is 7-4?','What is 3*5?','What is 9/3?']
a=['14','20','3','15','3']

q_len = q.length
a_len = a.length


@que = rand(q_len)

puts "Que:" + q[@que]
c = gets.chomp
if c == a[@que] then
puts "Correct."
else
puts "Wrong! Answer is:" + a[@que]
end

end

puts "Randomly questions from Array:"
for i in  0..4
que_ans
end

OUTPUT:

Randomly questions from Array:
Que:What is 3*5?
3
Wrong! Answer is:15
Que:What is 3*5?
15
Correct.
Que:What is 7-4?
3
Correct.
Que:What is 5*4?
2
Wrong! Answer is:20
Que:What is 8+6?
14
Correct.
#methods with arguments

def ask(question,answer)
   
      i = 0
puts question
         ans=gets.chomp.to_i
      if ans==answer
             @true+=1
            puts "correct"
       else
             puts "wrong answer"
        end
 

 end
question=['what is 8+6','5*4?','7-4?','3*5','9/3']
answer=[14,20,3,15,3]
@true=0
for i in 0..4
ask(question[i],answer[i])
end
puts "true answer : #@true"


OUTPUT:

what is 8+6
3
wrong answer
5*4?
20
correct
7-4?
3
correct
3*5
15
correct
9/3
3
correct
true answer : 4



#random addition

def random_addition

@arg1=rand(-2..0)
@arg2=rand(98..100)

puts "Random addition of two numbers :"
puts "What is #@arg1 + #@arg2 ?"

@arg3 =@arg1.to_i + Integer(@arg2)
puts "#@arg3"

end

random_addition

OUTPUT:

Random addition of two numbers :
What is 0 + 100 ?
100


program for ruby:

#method#

def addition

@arg1=gets.chomp
@arg2=gets.chomp

puts "addition of two numbers :"
puts "What is  @arg1 + @arg2 ? "

@arg3 =@arg1.to_i - @arg2.to_i
puts "#@arg3"

end
puts "enter 2 nos"
addition

OUTPUT
enter 2 nos
23
3
addition of two numbers :
What is  @arg1 + @arg2 ?
20