By ear. Its how I taught myself how to play. I listen to something I like and try to play it. Try and try until I get it right. It helped with learning where each sound is on the fingerboard which makes learning songs even easier. When I have trouble learning how to play a song mainly because I can't figure out certain notes in a harmony, I slow down the song with a computer program to have better clarity of the notes. Tabs I used to look at for learning difficult unclear solos but I find that most of the songs I look at tabs for are played inconveniently due to the way they are tabbed. So I've stayws away from tabs unless its something tabbed by the artist of the song.
When I compose a song (saying compose since I don't actually write anything), I'm often playing random things on the guitar and if I manage to like what I'm playing, I play it enough times and to be sure I won't forget I type it into Guitar Pro. Some of the songs I compose are pieced together that way. Sometimes I kind of know how I want a song to sound like, so it just flows out.
Google the program Best Practice. It is a free open source program. It is awesome. I use it everyday. You can slow down songs without changing the pitch. You can also set loop points and loop a part over and over and slow it down till you get it just right. You can also change the tunning of the song rather than change the tuning of your guitar. Google it...if you haven't used it you should.