Displaying the calenday day I have this (working) code:

class CalendarDay

  attr_accessor :from_month, :to_month, :year

  def self.line_of_day_numbers(month,year,start,offset)
    @line=''
    @offset=offset
    finish = (start+6)-@offset
    self.first_line_padding(start)
    start-= @offset
    self.day_numbers(month,year,start,finish)
  end 

  private

  def self.first_line_padding(start)
    if start &lt; 7 
      @line=' ' * (@offset * 3)
      @offset=0
    end 
  end 
  ...


But the methods are tangled and there's a mix of instance and local variables.

Tests include:

it "shows the day numbers" do
  expect(CalendarDay.line_of_day_numbers(2,2000,1,2)).to eq '       1  2  3  4  5'
end
it "shows the day numbers" do
  expect(CalendarDay.line_of_day_numbers(10,2000,1,0)).to eq ' 1  2  3  4  5  6  7'
end
it "shows the day numbers" do
  expect(CalendarDay.line_of_day_numbers(1,2000,8,6)).to eq ' 2  3  4  5  6  7  8'
end
It looks like you want to create some helper functions as class methods.  If you do that, you probably want to use class variables (e.g. @@a) rather than instance variables.  I would like to suggest what I think may be a better way. 

First, convert the instance variables you created with attr_accessor to class instance variables (not to be confused with class variables).  You can do that like this:

class CalendarDay
  class &lt;&lt; self
    attr_accessor :from_month, :to_month, :year

    def line_of_day_numbers(month,year,start,offset)
      ...
      @sugar = 7
      x = 5
      @year = ..... 
      ...
    end
  end 
end


Now you can use CalendarDay.from_month. CalendarDay.year = 2007, and so on.  Here class &lt;&lt; self is opening CalendarDay's singleton class or metaclass.  (To be more precise, it sets self to that metaclass.)  You could add other class instance variables (@sugar), as well as local variables (x).  You can also add class instance methods, as I have done above.  You would invoke this method with:

CalendarDay.line_of_day_numbers(month,year,start,offset)


Notice that self. is not used in defining class instance methods.  That's because self is the class's metaclass when they are created.

Note that these are class instance variables and class instance methods, not class variables or instance variables or class methods or instance methods.  They are only available to the class object, CalendarDays.  If you were to create an instance of the class, cal_day = CalendarDay.new, you'd find cal_day would have no access to any of these class instance variables or class instance methods.

One of the nice things about doing it this way is that you can write your code between class &lt;&lt; self and end in the same way you'd write code for a class instance.  All instance variables, local variables and instance methods are available to the class only.

For the record, there are a few (equivalent) alternatives to the class &lt;&lt; self/end construct.  One is:

module CalendarDayModule
  attr_accessor :from_month, :to_month, :year

  def line_of_day_numbers(month,year,start,offset)
      ...
  end
end

class CalendarDay
  extend CalendarDayModule
end


I discussed that here. 

Beyond this, I can make no suggestions for improving your code without seeing more of it, day_numbers() in particular.  BTW, within your line_of_day_numbers() class method, neither  first_line_padding() nor day_numbers() need be preceded by self..